jfeliu007 / goplantuml

PlantUML Class Diagram Generator for golang projects
MIT License
1.77k stars 166 forks source link

panic: runtime error: index out of range #161

Open j1elo opened 9 months ago

j1elo commented 9 months ago

I'm afraid I found a runtime panic while trying to run with https://github.com/livekit/livekit. Hopefully this helps with improving goplantuml's parser.

Curiously, the web version worked fine for me: https://www.dumels.com/diagram/9409c9a6-9f34-4cdb-a15f-fd6256fb4019

But I'd like to also be able to run it locally.

Commands:

go get github.com/jfeliu007/goplantuml/parser
go install github.com/jfeliu007/goplantuml/cmd/goplantuml@latest
git clone https://github.com/livekit/livekit.git
cd livekit/
goplantuml -recursive .

Output:

panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/jfeliu007/goplantuml/parser.(*Struct).AddField(0xc0002ef1f0, 0xc0002b6180, 0xc00020d278?)
        /home/work/golang/pkg/mod/github.com/jfeliu007/goplantuml@v1.6.2/parser/struct.go:99 +0x270
github.com/jfeliu007/goplantuml/parser.handleGenDecStructType(0xc0000b80f0, {0xc00020d278, 0x11}, 0x18?)
        /home/work/golang/pkg/mod/github.com/jfeliu007/goplantuml@v1.6.2/parser/class_parser.go:300 +0x65
github.com/jfeliu007/goplantuml/parser.(*ClassParser).processSpec(0xc0000b80f0, {0x60cee8?, 0xc0002b60c0?})
        /home/work/golang/pkg/mod/github.com/jfeliu007/goplantuml@v1.6.2/parser/class_parser.go:340 +0x9b
github.com/jfeliu007/goplantuml/parser.(*ClassParser).handleGenDecl(...)
        /home/work/golang/pkg/mod/github.com/jfeliu007/goplantuml@v1.6.2/parser/class_parser.go:326
github.com/jfeliu007/goplantuml/parser.(*ClassParser).parseFileDeclarations(0x589f20?, {0x60ca98?, 0xc0002b6340?})
        /home/work/golang/pkg/mod/github.com/jfeliu007/goplantuml@v1.6.2/parser/class_parser.go:262 +0x8d
github.com/jfeliu007/goplantuml/parser.(*ClassParser).parsePackage(0xc0000b80f0, {0x60c038?, 0xc0001fad20})
        /home/work/golang/pkg/mod/github.com/jfeliu007/goplantuml@v1.6.2/parser/class_parser.go:232 +0x398
github.com/jfeliu007/goplantuml/parser.(*ClassParser).parseDirectory(0x0?, {0xc0001ea180, 0x38})
        /home/work/golang/pkg/mod/github.com/jfeliu007/goplantuml@v1.6.2/parser/class_parser.go:253 +0xd8
github.com/jfeliu007/goplantuml/parser.NewClassDiagramWithOptions.func1({0xc0001ea180, 0x38}, {0x60d5f0, 0xc0001f04e0}, {0x0?, 0x0?})
        /home/work/golang/pkg/mod/github.com/jfeliu007/goplantuml@v1.6.2/parser/class_parser.go:168 +0x10d
github.com/spf13/afero.walk({0x60e200, 0x751f90}, {0xc0001ea180, 0x38}, {0x60d5f0, 0xc0001f04e0}, 0xc000173ab0)
        /home/work/golang/pkg/mod/github.com/spf13/afero@v1.8.2/path.go:44 +0x78
github.com/spf13/afero.walk({0x60e200, 0x751f90}, {0xc0000cac90, 0x30}, {0x60d5f0, 0xc00017a410}, 0xc000173ab0)
        /home/work/golang/pkg/mod/github.com/spf13/afero@v1.8.2/path.go:69 +0x32d
github.com/spf13/afero.walk({0x60e200, 0x751f90}, {0xc0000ca120, 0x2c}, {0x60d5f0, 0xc0000ad1e0}, 0xc000173ab0)
        /home/work/golang/pkg/mod/github.com/spf13/afero@v1.8.2/path.go:69 +0x32d
github.com/spf13/afero.Walk({0x60e200, 0x751f90}, {0xc0000ca120, 0x2c}, 0xc0000c5ab0)
        /home/work/golang/pkg/mod/github.com/spf13/afero@v1.8.2/path.go:105 +0x88
github.com/jfeliu007/goplantuml/parser.NewClassDiagramWithOptions(0xc000173c60)
        /home/work/golang/pkg/mod/github.com/jfeliu007/goplantuml@v1.6.2/parser/class_parser.go:157 +0x2d2
github.com/jfeliu007/goplantuml/parser.NewClassDiagram({0xc0000a0dc0?, 0xc0000c5e70?, 0x8?}, {0x751f90?, 0x0?, 0x1f?}, 0x47?)
        /home/work/golang/pkg/mod/github.com/jfeliu007/goplantuml@v1.6.2/parser/class_parser.go:208 +0xa5
main.main()
        /home/work/golang/pkg/mod/github.com/jfeliu007/goplantuml@v1.6.2/cmd/goplantuml/main.go:102 +0xdb0

Other info:

$ go version
go version go1.20.6 linux/amd64

Running on Ubuntu 20.04