New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Segmentation fault running swag init
after 1.8.5 release
#1309
Comments
I got this panic while trying to use it in GitHub Actions too today. Run swag init --parseDependency --parseInternal
swag init --parseDependency --parseInternal
shell: /usr/bin/bash -e {0}
[2](<org>/<repo>/runs/8029066662?check_suite_focus=true#step:9:2)022/08/26 0[3](<org>/<repo>/runs/8029066662?check_suite_focus=true#step:9:3):01:17 Generate swagger docs....
2022/08/26 03:01:17 Generate general API Info, search dir:./
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x87dc68]
goroutine 1 [running]:
github.com/swaggo/swag.(*PackagesDefinitions).parseFunctionScopedTypesFromFile(0xc0000a2798, 0xc002bc[4](<org>/<repo>/runs/8029066662?check_suite_focus=true#step:9:5)900, {0xc000b34c84, 0xa}, 0xc0163b[5](<org>/<repo>/runs/8029066662?check_suite_focus=true#step:9:6)b[6](<org>/<repo>/runs/8029066662?check_suite_focus=true#step:9:7)0)
/home/runner/go/pkg/mod/github.com/swaggo/swag@v1.8.5/packages.go:168 +0xa8
github.com/swaggo/swag.(*PackagesDefinitions).ParseTypes(0xc0000a2[7](<org>/<repo>/runs/8029066662?check_suite_focus=true#step:9:8)9[8](<org>/<repo>/runs/8029066662?check_suite_focus=true#step:9:9))
/home/runner/go/pkg/mod/github.com/swaggo/swag@v1.8.5/packages.go:110 +0xc[9](<org>/<repo>/runs/8029066662?check_suite_focus=true#step:9:10)
github.com/swaggo/swag.(*Parser).ParseAPIMultiSearchDir(0xc0001582a0, {0xc00014bfc0?, 0x1?, 0x0?}, {0x981e72?, 0x7?}, 0x64)
/home/runner/go/pkg/mod/github.com/swaggo/swag@v1.8.5/parser.go:362 +0x3bf
github.com/swaggo/swag/gen.(*Gen).Build(0xc0001518f0, 0xc000152c30)
/home/runner/go/pkg/mod/github.com/swaggo/swag@v1.8.5/gen/gen.go:177 +0x5c9
main.initAction(0xc000[12](<org>/<repo>/runs/8029066662?check_suite_focus=true#step:9:13)1680?)
/home/runner/go/pkg/mod/github.com/swaggo/swag@v1.8.5/cmd/swag/main.go:151 +0x757
github.com/urfave/cli/v2.(*Command).Run(0xc000128ea0, 0xc000166380)
/home/runner/go/pkg/mod/github.com/urfave/cli/v2@v2.3.0/command.go:163 +0x5dc
github.com/urfave/cli/v2.(*App).RunContext(0xc0001601a0, {0xa56670?, 0xc0000a8000}, {0xc000086040, 0x4, 0x4})
/home/runner/go/pkg/mod/github.com/urfave/cli/v2@v2.3.0/app.go:3[13](<org>/<repo>/runs/8029066662?check_suite_focus=true#step:9:14) +0xb7d
github.com/urfave/cli/v2.(*App).Run(...)
/home/runner/go/pkg/mod/github.com/urfave/cli/v2@v2.3.0/app.go:224
main.main()
/home/runner/go/pkg/mod/github.com/swaggo/swag@v1.8.5/cmd/swag/main.go:2[21](<org>/<repo>/runs/8029066662?check_suite_focus=true#step:9:22) +0x5c5
Error: Process completed with exit code 2. |
we are seeing same go 1.18 + ubuntu 20 |
ping @ubogdan |
the PR that is breaking this is maybe #1283 |
I also got this panic too! 1.8.5. trace: panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x1477b68]
goroutine 1 [running]:
github.com/swaggo/swag.(*PackagesDefinitions).parseFunctionScopedTypesFromFile(0xc000010858, 0xc002954000, {0xc0010d2570, 0x15}, 0xc002e7b8f0)
/go/src/github.com/swaggo/swag/packages.go:168 +0xa8
github.com/swaggo/swag.(*PackagesDefinitions).ParseTypes(0xc000010858)
/go/src/github.com/swaggo/swag/packages.go:110 +0xc9
github.com/swaggo/swag.(*Parser).ParseAPIMultiSearchDir(0xc00019e2a0, {0xc00011f600?, 0x2?, 0x0?}, {0x7ff7bfeff2d5?, 0x11?}, 0x64)
/go/src/github.com/swaggo/swag/parser.go:362 +0x3bf
github.com/swaggo/swag/gen.(*Gen).Build(0xc0001a14d0, 0xc000198a90)
/go/src/github.com/swaggo/swag/gen/gen.go:177 +0x5c9
main.initAction(0xc000171680?)
/go/src/github.com/swaggo/swag/cmd/swag/main.go:151 +0x757
github.com/urfave/cli/v2.(*Command).Run(0xc000176c60, 0xc0001c6140)
/go/pkg/mod/github.com/urfave/cli/v2@v2.3.0/command.go:163 +0x5dc
github.com/urfave/cli/v2.(*App).RunContext(0xc000194820, {0x164fb10?, 0xc000026138}, {0xc000022090, 0x9, 0x9})
/go/pkg/mod/github.com/urfave/cli/v2@v2.3.0/app.go:313 +0xb7d
github.com/urfave/cli/v2.(*App).Run(...)
/go/pkg/mod/github.com/urfave/cli/v2@v2.3.0/app.go:224
main.main()
/go/src/github.com/swaggo/swag/cmd/swag/main.go:221 +0x5c5 go1.19 darwin/amd64 |
Same here
|
if funcDeclaration, ok := astDeclaration.(*ast.FuncDecl); ok { In this kind of checks, we should check funcDeclaration is not nil I was thinking the if funcDeclaration, _ := astDeclaration.(*ast.FuncDecl); funcDeclaration != nil { EDITED Looks like I am wrong in here, not working like that in just sending nil without typecasting the pointer stuct of nil, anyways:) |
Also experiencing this issue with the latest release. |
Same here worked for 2022/08/26 13:12:22 Generate swagger docs....
2022/08/26 13:12:22 Generate general API Info, search dir:./
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x8 pc=0x10114a988]
goroutine 1 [running]:
github.com/swaggo/swag.(*PackagesDefinitions).parseFunctionScopedTypesFromFile(0x140001a8828, 0x14000d9c280, {0x140008c5bc0, 0x15}, 0x14001fce690)
/Users/mikolaj/go/pkg/mod/github.com/swaggo/swag@v1.8.5/packages.go:168 +0x98
github.com/swaggo/swag.(*PackagesDefinitions).ParseTypes(0x140001a8828)
/Users/mikolaj/go/pkg/mod/github.com/swaggo/swag@v1.8.5/packages.go:110 +0xa0
github.com/swaggo/swag.(*Parser).ParseAPIMultiSearchDir(0x140002602a0, {0x1400028e070?, 0x1?, 0x0?}, {0x1011741a1?, 0x7?}, 0x64)
/Users/mikolaj/go/pkg/mod/github.com/swaggo/swag@v1.8.5/parser.go:362 +0x2b0
github.com/swaggo/swag/gen.(*Gen).Build(0x140002599e0, 0x1400025f2b0)
/Users/mikolaj/go/pkg/mod/github.com/swaggo/swag@v1.8.5/gen/gen.go:177 +0x4a8
main.initAction(0x1400022f8c0?)
/Users/mikolaj/go/pkg/mod/github.com/swaggo/swag@v1.8.5/cmd/swag/main.go:151 +0x658
github.com/urfave/cli/v2.(*Command).Run(0x1400022d560, 0x1400026c4c0)
/Users/mikolaj/go/pkg/mod/github.com/urfave/cli/v2@v2.3.0/command.go:163 +0x50c
github.com/urfave/cli/v2.(*App).RunContext(0x140002531e0, {0x1013199a0?, 0x140001b4008}, {0x1400019c180, 0x3, 0x3})
/Users/mikolaj/go/pkg/mod/github.com/urfave/cli/v2@v2.3.0/app.go:313 +0x888
github.com/urfave/cli/v2.(*App).Run(...)
/Users/mikolaj/go/pkg/mod/github.com/urfave/cli/v2@v2.3.0/app.go:224
main.main()
/Users/mikolaj/go/pkg/mod/github.com/swaggo/swag@v1.8.5/cmd/swag/main.go:221 +0x660 After downgrading via |
Hi all, this is related to a development that was done by me merged lastly. I am investigating it right now, and working on it 🙏 Edit: I just saw that it is fixed here: #1310 The root cause of this error is that the functions that have no body declaration. For example when you declare a function with
I wrote a story about this problem: https://itnext.io/my-contribution-to-a-popular-open-source-package-caused-a-panic-in-golang-projects-4d34394df4cf |
v1.8.6 released. |
Verified as fixed with v1.8.6 Thanks. |
Fixed in 1.8.6, however there was a regression on 1.8.8: [10:37:45] tsampson:cloud-api git:(main) $ swag --version
swag version v1.8.8
[10:38:47] tsampson:cloud-api git:(main) $ swag init --parseDependency --parseInternal --parseDepth 1 --dir ./cmd/api
2022/12/05 10:39:00 Generate swagger docs....
2022/12/05 10:39:00 Generate general API Info, search dir:./cmd/api
panic: runtime error: negative shift amount
goroutine 1 [running]:
github.com/swaggo/swag.(*PackageDefinitions).evaluateConstValue(0xc001a93bd0, 0xc00c6f7a70?, 0xc00ee44d10?, {0x165c920?, 0xc001ad2090?}, {0x165aec0, 0xc0001bf820}, 0x55?)
/Users/tsampson/go/pkg/mod/github.com/swaggo/swag@v1.8.8/package.go:146 +0x102b
github.com/swaggo/swag.(*PackagesDefinitions).EvaluateConstValue(0xc00bffb698?, 0xc001a93bd0, 0xc01a6a73c0, 0x0)
/Users/tsampson/go/pkg/mod/github.com/swaggo/swag@v1.8.8/packages.go:282 +0x19d
github.com/swaggo/swag.(*PackagesDefinitions).evaluateAllConstVariables(...)
/Users/tsampson/go/pkg/mod/github.com/swaggo/swag@v1.8.8/packages.go:265
github.com/swaggo/swag.(*PackagesDefinitions).ParseTypes(0xc0001bf820)
/Users/tsampson/go/pkg/mod/github.com/swaggo/swag@v1.8.8/packages.go:110 +0x254
github.com/swaggo/swag.(*Parser).ParseAPIMultiSearchDir(0xc0002820c0, {0xc00027e0d0?, 0x1?, 0x0?}, {0x1589292?, 0x7?}, 0x1)
/Users/tsampson/go/pkg/mod/github.com/swaggo/swag@v1.8.8/parser.go:375 +0x3bf
github.com/swaggo/swag/gen.(*Gen).Build(0xc000249920, 0xc0002442a0)
/Users/tsampson/go/pkg/mod/github.com/swaggo/swag@v1.8.8/gen/gen.go:182 +0x637
main.initAction(0xc00026c780?)
/Users/tsampson/go/pkg/mod/github.com/swaggo/swag@v1.8.8/cmd/swag/main.go:158 +0x7bd
github.com/urfave/cli/v2.(*Command).Run(0xc000222a20, 0xc00026a300)
/Users/tsampson/go/pkg/mod/github.com/urfave/cli/v2@v2.3.0/command.go:163 +0x5dc
github.com/urfave/cli/v2.(*App).RunContext(0xc000187d40, {0x165d930?, 0xc0001a6008}, {0xc0001ae000, 0x8, 0x8})
/Users/tsampson/go/pkg/mod/github.com/urfave/cli/v2@v2.3.0/app.go:313 +0xb7d
github.com/urfave/cli/v2.(*App).Run(...)
/Users/tsampson/go/pkg/mod/github.com/urfave/cli/v2@v2.3.0/app.go:224
main.main()
/Users/tsampson/go/pkg/mod/github.com/swaggo/swag@v1.8.8/cmd/swag/main.go:229 +0x5c5 [10:39:03] tsampson:cloud-api git:(main) $ go install github.com/swaggo/swag/cmd/swag@v1.8.6
[10:39:48] tsampson:cloud-api git:(main) $ swag --version
swag version v1.8.6
[10:39:51] tsampson:cloud-api git:(main) $ swag init --parseDependency --parseInternal --parseDepth 1 --dir ./cmd/api
2022/12/05 10:39:54 Generate swagger docs....
2022/12/05 10:39:54 Generate general API Info, search dir:./cmd/api
2022/12/05 10:39:57 Generating errs.HTTPError
2022/12/05 10:39:57 Generating schema.Health
2022/12/05 10:39:57 Generating version.Metadata
2022/12/05 10:39:57 create docs.go at docs/docs.go
2022/12/05 10:39:57 create swagger.json at docs/swagger.json
2022/12/05 10:39:58 create swagger.yaml at docs/swagger.yaml |
Describe the bug
Since 1.8.5 was released, when running
swag init --parseDependency true
on my code I encounter a segfault. After switching back to 1.8.4 (or other versions in the 1.8 line) the command completes successfully.To Reproduce
I'm unable to share the entire code this happens on. I will see if I can isolate this to a small code sample I can share.
Stack trace
Your swag version
1.8.5 (1.8.4 and earlier worked)
Go version: 1.18
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: