give err msg for invalid edge style

This commit is contained in:
Alexander Wang 2023-03-06 22:42:52 -08:00
parent 4e53c27aff
commit 9199554800
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
5 changed files with 48 additions and 0 deletions

View file

@ -3,6 +3,7 @@
#### Improvements 🧹
- ELK nodes with > 1 connection grow to ensure padding around ports [#981](https://github.com/terrastruct/d2/pull/981)
- Using a style keyword incorrectly in connections returns clear error message [#989](https://github.com/terrastruct/d2/pull/989)
#### Bugfixes ⛑️

View file

@ -450,6 +450,11 @@ func (c *compiler) compileEdge(obj *d2graph.Object, e *d2ir.Edge) {
func (c *compiler) compileEdgeField(edge *d2graph.Edge, f *d2ir.Field) {
keyword := strings.ToLower(f.Name)
_, isStyleReserved := d2graph.StyleKeywords[keyword]
if isStyleReserved {
c.errorf(f.LastRef().AST(), "%v must be style.%v", f.Name, f.Name)
return
}
_, isReserved := d2graph.SimpleReservedKeywords[keyword]
if isReserved {
c.compileReserved(edge.Attributes, f)

View file

@ -1117,6 +1117,24 @@ x: {
`,
expErr: `d2/testdata/d2compiler/TestCompile/shape_edge_style.d2:3:2: key "animated" can only be applied to edges`,
},
{
name: "edge_invalid_style",
text: `x -> y: {
opacity: 0.5
}
`,
expErr: `d2/testdata/d2compiler/TestCompile/edge_invalid_style.d2:2:3: opacity must be style.opacity`,
},
{
name: "obj_invalid_style",
text: `x: {
opacity: 0.5
}
`,
expErr: `d2/testdata/d2compiler/TestCompile/obj_invalid_style.d2:2:3: opacity must be style.opacity`,
},
{
name: "edge_chain_map",

View file

@ -0,0 +1,12 @@
{
"graph": null,
"err": {
"ioerr": null,
"errs": [
{
"range": "d2/testdata/d2compiler/TestCompile/edge_invalid_style.d2,1:2:12-1:9:19",
"errmsg": "d2/testdata/d2compiler/TestCompile/edge_invalid_style.d2:2:3: opacity must be style.opacity"
}
]
}
}

View file

@ -0,0 +1,12 @@
{
"graph": null,
"err": {
"ioerr": null,
"errs": [
{
"range": "d2/testdata/d2compiler/TestCompile/obj_invalid_style.d2,1:2:7-1:9:14",
"errmsg": "d2/testdata/d2compiler/TestCompile/obj_invalid_style.d2:2:3: opacity must be style.opacity"
}
]
}
}