emicklei / dot

Go package for writing descriptions using the Graphviz DOT and Mermaid language
MIT License
281 stars 19 forks source link

[MERMAID] Shape attributes on node causes the mermaid exporter to crash #40

Open john-scalingo opened 1 day ago

john-scalingo commented 1 day ago

The mermaid exporter crashes when there's a shape attribute on a node.

This is due to this code: https://github.com/emicklei/dot/blob/master/mermaid.go#L82-L84

Which expect the shape attribute to be of type shape where it can not be. This type is always string.

This can be easily reproduced with:

    graph := dot.NewGraph(dot.Directed)
    graph.Node("A").Box()
    graph.Edge(graph.Node("A"), graph.Node("B"))

    fmt.Println(dot.MermaidGraph(graph, dot.MermaidTopDown))

Which causes the following error:

panic: interface conversion: interface {} is string, not dot.shape

goroutine 1 [running]:
github.com/emicklei/dot.diagramGraph(0xc0000a8000, 0xc00007e020)
        /home/john/gocode/pkg/mod/github.com/emicklei/dot@v1.6.3/mermaid.go:83 +0xb94
github.com/emicklei/dot.diagram(0xc0000a8000, {0x4bd97a, 0x5}, 0x1)
        /home/john/gocode/pkg/mod/github.com/emicklei/dot@v1.6.3/mermaid.go:67 +0x545
github.com/emicklei/dot.MermaidGraph(...)
        /home/john/gocode/pkg/mod/github.com/emicklei/dot@v1.6.3/mermaid.go:39
main.main()
        /home/john/Documents/dotbug/test.go:14 +0x3b9
exit status 2
emicklei commented 1 day ago

thank you for reporting this. I will work on a solution

john-scalingo commented 1 day ago

I confirm that release 1.6.4 seems to fix the issue.

Your reactivity is really impressive ! Thanks a lot for your help and for this awesome package.