Merge pull request #1255 from alixander/add-layout-specific-err

add more detailed error msg for layout-specific err
This commit is contained in:
Alexander Wang 2023-04-27 14:13:04 -07:00 committed by GitHub
commit 22243665e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 10 deletions

View file

@ -35,12 +35,12 @@ func FeatureSupportCheck(info *PluginInfo, g *d2graph.Graph) error {
for _, obj := range g.Objects { for _, obj := range g.Objects {
if obj.Top != nil || obj.Left != nil { if obj.Top != nil || obj.Left != nil {
if _, ok := featureMap[TOP_LEFT]; !ok { if _, ok := featureMap[TOP_LEFT]; !ok {
return fmt.Errorf(`Object "%s" has attribute "top" and/or "left" set, but layout engine "%s" does not support locked positions.`, obj.AbsID(), info.Name) return fmt.Errorf(`Object "%s" has attribute "top" and/or "left" set, but layout engine "%s" does not support locked positions. See https://d2lang.com/tour/layouts/#layout-specific-functionality for more.`, obj.AbsID(), info.Name)
} }
} }
if (obj.WidthAttr != nil || obj.HeightAttr != nil) && len(obj.ChildrenArray) > 0 { if (obj.WidthAttr != nil || obj.HeightAttr != nil) && len(obj.ChildrenArray) > 0 {
if _, ok := featureMap[CONTAINER_DIMENSIONS]; !ok { if _, ok := featureMap[CONTAINER_DIMENSIONS]; !ok {
return fmt.Errorf(`Object "%s" has attribute "width" and/or "height" set, but layout engine "%s" does not support dimensions set on containers.`, obj.AbsID(), info.Name) return fmt.Errorf(`Object "%s" has attribute "width" and/or "height" set, but layout engine "%s" does not support dimensions set on containers. See https://d2lang.com/tour/layouts/#layout-specific-functionality for more.`, obj.AbsID(), info.Name)
} }
} }
@ -48,7 +48,7 @@ func FeatureSupportCheck(info *PluginInfo, g *d2graph.Graph) error {
_, isKey := g.Root.HasChild(d2graph.Key(obj.NearKey)) _, isKey := g.Root.HasChild(d2graph.Key(obj.NearKey))
if isKey { if isKey {
if _, ok := featureMap[NEAR_OBJECT]; !ok { if _, ok := featureMap[NEAR_OBJECT]; !ok {
return fmt.Errorf(`Object "%s" has "near" set to another object, but layout engine "%s" only supports constant values for "near".`, obj.AbsID(), info.Name) return fmt.Errorf(`Object "%s" has "near" set to another object, but layout engine "%s" only supports constant values for "near". See https://d2lang.com/tour/layouts/#layout-specific-functionality for more.`, obj.AbsID(), info.Name)
} }
} }
} }
@ -63,10 +63,10 @@ func FeatureSupportCheck(info *PluginInfo, g *d2graph.Graph) error {
continue continue
} }
if e.Src == e.Dst { if e.Src == e.Dst {
return fmt.Errorf(`Connection "%s" is a self loop on a container, but layout engine "%s" does not support this.`, e.AbsID(), info.Name) return fmt.Errorf(`Connection "%s" is a self loop on a container, but layout engine "%s" does not support this. See https://d2lang.com/tour/layouts/#layout-specific-functionality for more.`, e.AbsID(), info.Name)
} }
if e.Src.IsDescendantOf(e.Dst) || e.Dst.IsDescendantOf(e.Src) { if e.Src.IsDescendantOf(e.Dst) || e.Dst.IsDescendantOf(e.Src) {
return fmt.Errorf(`Connection "%s" goes from a container to a descendant, but layout engine "%s" does not support this.`, e.AbsID(), info.Name) return fmt.Errorf(`Connection "%s" goes from a container to a descendant, but layout engine "%s" does not support this. See https://d2lang.com/tour/layouts/#layout-specific-functionality for more.`, e.AbsID(), info.Name)
} }
} }
} }

View file

@ -723,7 +723,7 @@ eee.shape: document
eee <- aaa.ccc eee <- aaa.ccc
(eee <- aaa.ccc)[0]: '222' (eee <- aaa.ccc)[0]: '222'
`, `,
dagreFeatureError: `Connection "(aaa.ccc -- aaa)[0]" goes from a container to a descendant, but layout engine "dagre" does not support this.`, dagreFeatureError: `Connection "(aaa.ccc -- aaa)[0]" goes from a container to a descendant, but layout engine "dagre" does not support this. See https://d2lang.com/tour/layouts/#layout-specific-functionality for more.`,
}, },
{ {
name: "chaos2", name: "chaos2",
@ -2133,7 +2133,7 @@ c: {
a a
} }
`, `,
dagreFeatureError: `Object "a" has attribute "width" and/or "height" set, but layout engine "dagre" does not support dimensions set on containers.`, dagreFeatureError: `Object "a" has attribute "width" and/or "height" set, but layout engine "dagre" does not support dimensions set on containers. See https://d2lang.com/tour/layouts/#layout-specific-functionality for more.`,
}, },
{ {
name: "crow_foot_arrowhead", name: "crow_foot_arrowhead",

View file

@ -14,14 +14,14 @@ func testTodo(t *testing.T) {
container.first -> container.second: 1->2 container.first -> container.second: 1->2
container -> container.second: c->2 container -> container.second: c->2
`, `,
dagreFeatureError: `Connection "(container -> container.second)[0]" goes from a container to a descendant, but layout engine "dagre" does not support this.`, dagreFeatureError: `Connection "(container -> container.second)[0]" goes from a container to a descendant, but layout engine "dagre" does not support this. See https://d2lang.com/tour/layouts/#layout-specific-functionality for more.`,
}, },
{ {
name: "child_parent_edges", name: "child_parent_edges",
script: `a.b -> a script: `a.b -> a
a.b -> a.b.c a.b -> a.b.c
a.b.c.d -> a.b`, a.b.c.d -> a.b`,
dagreFeatureError: `Connection "(a.b -> a)[0]" goes from a container to a descendant, but layout engine "dagre" does not support this.`, dagreFeatureError: `Connection "(a.b -> a)[0]" goes from a container to a descendant, but layout engine "dagre" does not support this. See https://d2lang.com/tour/layouts/#layout-specific-functionality for more.`,
}, },
{ {
name: "container_label_loop", name: "container_label_loop",
@ -29,7 +29,7 @@ a.b.c.d -> a.b`,
b -> c b -> c
} }
a -> a`, a -> a`,
dagreFeatureError: `Connection "(a -> a)[0]" is a self loop on a container, but layout engine "dagre" does not support this.`, dagreFeatureError: `Connection "(a -> a)[0]" is a self loop on a container, but layout engine "dagre" does not support this. See https://d2lang.com/tour/layouts/#layout-specific-functionality for more.`,
}, },
{ {
// as nesting gets deeper, the groups advance towards `c` and may overlap its lifeline // as nesting gets deeper, the groups advance towards `c` and may overlap its lifeline