fix sql constraint array panic
This commit is contained in:
parent
4eda74ada4
commit
3a6834662d
3 changed files with 26 additions and 0 deletions
|
|
@ -688,6 +688,10 @@ func (c *compiler) compileSQLTable(obj *d2graph.Object) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if n.MapKey.Key.Path[0].Unbox().ScalarString() == "constraint" {
|
if n.MapKey.Key.Path[0].Unbox().ScalarString() == "constraint" {
|
||||||
|
if n.MapKey.Value.StringBox().Unbox() == nil {
|
||||||
|
c.errorf(n.MapKey.GetRange().Start, n.MapKey.GetRange().End, "constraint value must be a string")
|
||||||
|
return
|
||||||
|
}
|
||||||
d2Col.Constraint = n.MapKey.Value.StringBox().Unbox().ScalarString()
|
d2Col.Constraint = n.MapKey.Value.StringBox().Unbox().ScalarString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1668,6 +1668,16 @@ choo: {
|
||||||
tassert.Equal(t, 3, len(g.Objects))
|
tassert.Equal(t, 3, len(g.Objects))
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "sql-panic",
|
||||||
|
text: `test {
|
||||||
|
shape: sql_table
|
||||||
|
test_id: varchar(64) {constraint: [primary_key, foreign_key]}
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
expErr: `d2/testdata/d2compiler/TestCompile/sql-panic.d2:3:27: constraint value must be a string
|
||||||
|
`,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
|
|
|
||||||
12
testdata/d2compiler/TestCompile/sql-panic.exp.json
generated
vendored
Normal file
12
testdata/d2compiler/TestCompile/sql-panic.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"graph": null,
|
||||||
|
"err": {
|
||||||
|
"ioerr": null,
|
||||||
|
"errs": [
|
||||||
|
{
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/sql-panic.d2,2:26:54-2:64:92",
|
||||||
|
"errmsg": "d2/testdata/d2compiler/TestCompile/sql-panic.d2:3:27: constraint value must be a string"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue