Merge pull request #783 from alixander/steps-panic

fix steps panic
This commit is contained in:
Alexander Wang 2023-02-22 16:27:39 -08:00 committed by GitHub
commit a73438072e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 3 deletions

View file

@ -18,3 +18,4 @@
- Fixes rare possibility of rendered connections being hidden or cut off. [#828](https://github.com/terrastruct/d2/pull/828)
- Creating nested children within `sql_table` and `class` shapes are now prevented (caused confusion when accidentally done). [#834](https://github.com/terrastruct/d2/pull/834)
- Fixes graph deserialization bug. [#837](https://github.com/terrastruct/d2/pull/837)
- `steps` with non-map fields could cause panics. [#783](https://github.com/terrastruct/d2/pull/783)

View file

@ -38,7 +38,8 @@ func (c *compiler) compileScenarios(m *Map) {
}
for _, sf := range scenarios.Fields {
if sf.Map() == nil {
if sf.Map() == nil || sf.Primary() != nil {
c.errorf(sf.References[0].Context.Key, "invalid scenario")
continue
}
base := m.CopyBase(sf)
@ -59,8 +60,9 @@ func (c *compiler) compileSteps(m *Map) {
return
}
for i, sf := range steps.Fields {
if sf.Map() == nil {
continue
if sf.Map() == nil || sf.Primary() != nil {
c.errorf(sf.References[0].Context.Key, "invalid step")
break
}
var base *Map
if i == 0 {

View file

@ -420,6 +420,22 @@ steps: {
assertQuery(t, m, 0, 0, nil, "steps.nuclear.quiche")
},
},
{
name: "steps_panic",
run: func(t testing.TB) {
_, err := compile(t, `steps: {
shape: sql_table
id: int {constraint: primary_key}
}
scenarios: {
shape: sql_table
hey: int {constraint: primary_key}
}`)
assert.ErrorString(t, err, `TestCompile/steps/steps_panic.d2:6:3: invalid scenario
TestCompile/steps/steps_panic.d2:7:3: invalid scenario
TestCompile/steps/steps_panic.d2:2:3: invalid step`)
},
},
{
name: "recursive",
run: func(t testing.TB) {