Skip to content
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

crash with --v3.1 when generating #1979

Open
bernhardreiter opened this issue Feb 14, 2025 · 0 comments
Open

crash with --v3.1 when generating #1979

bernhardreiter opened this issue Feb 14, 2025 · 0 comments

Comments

@bernhardreiter
Copy link

Runtime error: invalid memory address or nil pointer dereference
occurs when trying

swag init -g docs.go --parseDependency --parseInternal --v3.1

To reproduce

  1. Checkout 04a42cfacf87cb9bae4cdca708c4f4ee76dd6a6b of https://github.com/ISDuBA/ISDuBA
  2. cd into directory
  3. run `go generate ./..' or cd into pkg/web and run the above command.
  4. See error

Expected behavior
No crash. The openapi file gets generated.

Your swag version
2.0.0-rc4

Your go version
go1.24.0 linux/amd64

Additional context
Removing file https://github.com/ISDuBA/ISDuBA/blob/04a42cfacf87cb9bae4cdca708c4f4ee76dd6a6b/pkg/web/sources.go
from the directory will remove the crash, giving the log it seems that the struct sourceAge is cause of the problem.

Here is a full log

~/isduba-git/pkg/web$ swag init -g docs.go --parseDependency --parseInternal --v3.1
Swag version:  v2.0.0
2025/02/14 21:15:50 Generate swagger docs....
2025/02/14 21:15:50 Generate general API Info, search dir:./
get pkg name for directory: ./
2025/02/14 21:15:54 warning: failed to evaluate const mProfCycleWrap at /usr/local/go/src/runtime/mprof.go:179:7, reflect: call of reflect.Value.Len on zero Value
2025/02/14 21:15:54 Generating web.about.info
2025/02/14 21:15:54 Generating models.PublishersTLPs
2025/02/14 21:15:54 Generating models.TLP
2025/02/14 21:15:54 Generating config.Client
2025/02/14 21:15:54 Generating time.Duration
2025/02/14 21:15:54 Generating models.Success
2025/02/14 21:15:54 Generating models.Error
2025/02/14 21:15:54 Generating web.advisoryStates
2025/02/14 21:15:54 Generating models.AdvisoryState
2025/02/14 21:15:54 Generating models.Workflow
2025/02/14 21:15:54 Generating web.viewEvents.event
2025/02/14 21:15:54 Generating models.Event
2025/02/14 21:15:54 Generating web.argumentedAggregator
2025/02/14 21:15:54 Generating encoding_json.RawMessage
2025/02/14 21:15:54 Generating web.custom
2025/02/14 21:15:54 Generating sources.SourceSubscriptions
2025/02/14 21:15:54 Generating sources.SourceSubscription
2025/02/14 21:15:54 Generating sources.FeedSubscription
2025/02/14 21:15:54 Generating web.viewAggregators.aggregator
2025/02/14 21:15:54 Generating models.ID
2025/02/14 21:15:54 Generating web.createComment.commentResult
2025/02/14 21:15:54 Generating sql.NullString
2025/02/14 21:15:54 Generating web.comment
2025/02/14 21:15:54 Generating forwarder.ForwardTarget
2025/02/14 21:15:54 Generating web.overviewDocuments.documentResult
2025/02/14 21:15:54 Generating web.overviewEvents.events
2025/02/14 21:15:54 Generating models.StoredQuery
2025/02/14 21:15:54 Generating query.ParserMode
2025/02/14 21:15:54 Generating models.WorkflowRole
2025/02/14 21:15:54 Generating web.createStoredQuery.createResult
2025/02/14 21:15:54 Generating web.updateOrder.queryOrder
2025/02/14 21:15:54 Generating web.insertDefaultQueryExclusion.createResult
2025/02/14 21:15:54 Generating web.viewSources.sourcesResult
2025/02/14 21:15:54 Generating web.source
2025/02/14 21:15:54 Generating web.sourceAge
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x2b8 pc=0x8ff482]

goroutine 1 [running]:
github.com/swaggo/swag/v2.(*Parser).parseStructFieldV3(0xc00026ca00, 0xc0002ca6e0, 0xc000489a00)
        /home/ber/go/pkg/mod/github.com/swaggo/swag/[email protected]/parserv3.go:1006 +0x482
github.com/swaggo/swag/v2.(*Parser).parseStructV3(0xc00026ca00, 0xc0002ca6e0, 0xc0004ac120)
        /home/ber/go/pkg/mod/github.com/swaggo/swag/[email protected]/parserv3.go:885 +0xca
github.com/swaggo/swag/v2.(*Parser).parseTypeExprV3(0xc00026ca00, 0xb824ac?, {0xc6e420?, 0xc0004b20c0?}, 0x30?)
        /home/ber/go/pkg/mod/github.com/swaggo/swag/[email protected]/parserv3.go:808 +0x447
github.com/swaggo/swag/v2.(*Parser).ParseDefinitionV3(0xc00026ca00, 0xc00fe9c9c0)
        /home/ber/go/pkg/mod/github.com/swaggo/swag/[email protected]/parserv3.go:718 +0x405
github.com/swaggo/swag/v2.(*Parser).getTypeSchemaV3(0xc00026ca00, {0xc000487010, 0x6}, 0xc0002ca6e0, 0x1)
        /home/ber/go/pkg/mod/github.com/swaggo/swag/[email protected]/parserv3.go:669 +0xa06
github.com/swaggo/swag/v2.(*Parser).parseTypeExprV3(0xc00026ca00, 0xc010c086b8?, {0xc6e2d0?, 0xc0004afd00?}, 0xf6?)
        /home/ber/go/pkg/mod/github.com/swaggo/swag/[email protected]/parserv3.go:812 +0x3c7
github.com/swaggo/swag/v2.(*Parser).parseTypeExprV3(0xc00026ca00, 0x8cdc47?, {0xc6e330?, 0xc0004b26f0?}, 0x30?)
        /home/ber/go/pkg/mod/github.com/swaggo/swag/[email protected]/parserv3.go:820 +0x425
github.com/swaggo/swag/v2.(*Parser).parseTypeExprV3(0xc00026ca00, 0xc6e360?, {0xc6e360?, 0xc0004acab0}, 0x0?)
        /home/ber/go/pkg/mod/github.com/swaggo/swag/[email protected]/parserv3.go:834 +0x5f1
github.com/swaggo/swag/v2.(*Parser).parseStructFieldV3(0xc00026ca00, 0xc0002ca6e0, 0xc0004b4800)
        /home/ber/go/pkg/mod/github.com/swaggo/swag/[email protected]/parserv3.go:980 +0x354
github.com/swaggo/swag/v2.(*Parser).parseStructV3(0xc00026ca00, 0xc0002ca6e0, 0xc0004acae0)
        /home/ber/go/pkg/mod/github.com/swaggo/swag/[email protected]/parserv3.go:885 +0xca
github.com/swaggo/swag/v2.(*Parser).parseTypeExprV3(0xc00026ca00, 0xb824ac?, {0xc6e420?, 0xc0004b2708?}, 0x20?)
        /home/ber/go/pkg/mod/github.com/swaggo/swag/[email protected]/parserv3.go:808 +0x447
github.com/swaggo/swag/v2.(*Parser).ParseDefinitionV3(0xc00026ca00, 0xc00fe9cae0)
        /home/ber/go/pkg/mod/github.com/swaggo/swag/[email protected]/parserv3.go:718 +0x405
github.com/swaggo/swag/v2.(*Parser).getTypeSchemaV3(0xc00026ca00, {0xc000436b9a, 0x1d}, 0xc0002ca6e0, 0x1)
        /home/ber/go/pkg/mod/github.com/swaggo/swag/[email protected]/parserv3.go:669 +0xa06
github.com/swaggo/swag/v2.parseObjectSchemaV3(0xc00026ca00, {0xc000436b9a, 0x1d}, 0xc0002ca6e0)
        /home/ber/go/pkg/mod/github.com/swaggo/swag/[email protected]/operationv3.go:851 +0xf9d
github.com/swaggo/swag/v2.(*OperationV3).parseObjectSchema(...)
        /home/ber/go/pkg/mod/github.com/swaggo/swag/[email protected]/operationv3.go:791
github.com/swaggo/swag/v2.(*OperationV3).parseAPIObjectSchema(0xc0106dfc00, {0xc000436b8d, 0x2a}, {0xc000436b92, 0x6}, {0xc000436b9a, 0x1d}, 0xc0002ca6e0)
        /home/ber/go/pkg/mod/github.com/swaggo/swag/[email protected]/operationv3.go:705 +0x446
github.com/swaggo/swag/v2.(*OperationV3).ParseResponseComment(0xc0106dfc00, {0xc000436b8d, 0x2a}, 0xc0002ca6e0)
        /home/ber/go/pkg/mod/github.com/swaggo/swag/[email protected]/operationv3.go:939 +0x13d
github.com/swaggo/swag/v2.(*OperationV3).ParseComment(0xc0106dfc00, {0xc000436b80?, 0x1?}, 0xc0002ca6e0)
        /home/ber/go/pkg/mod/github.com/swaggo/swag/[email protected]/operationv3.go:88 +0x329
github.com/swaggo/swag/v2.(*Parser).ParseRouterAPIInfoV3(0xc00026ca00, 0xc0004e8900)
        /home/ber/go/pkg/mod/github.com/swaggo/swag/[email protected]/parserv3.go:514 +0x1b1
github.com/swaggo/swag/v2.(*PackagesDefinitions).RangeFiles(0xc00030aa50, 0xc010c09508)
        /home/ber/go/pkg/mod/github.com/swaggo/swag/[email protected]/packages.go:107 +0x33c
github.com/swaggo/swag/v2.(*Parser).ParseAPIMultiSearchDir(0xc00026ca00, {0xc0003151f0, 0x1, 0x0?}, {0x7ffeff50b5e3, 0x7}, 0x64)
        /home/ber/go/pkg/mod/github.com/swaggo/swag/[email protected]/parser.go:499 +0x63a
github.com/swaggo/swag/v2/gen.(*Gen).Build(0xc00030a750, 0xc000238180)
        /home/ber/go/pkg/mod/github.com/swaggo/swag/[email protected]/gen/gen.go:233 +0x7aa
main.initAction(0xc00027a100)
        /home/ber/go/pkg/mod/github.com/swaggo/swag/[email protected]/cmd/swag/main.go:249 +0xa08
github.com/urfave/cli/v2.(*Command).Run(0xc000248420, 0xc00027a100, {0xc000180960, 0x6, 0x6})
        /home/ber/go/pkg/mod/github.com/urfave/cli/[email protected]/command.go:274 +0x77b
github.com/urfave/cli/v2.(*Command).Run(0xc000248840, 0xc00019bf40, {0xc000138000, 0x7, 0x7})
        /home/ber/go/pkg/mod/github.com/urfave/cli/[email protected]/command.go:267 +0x9fc
github.com/urfave/cli/v2.(*App).RunContext(0xc000276000, {0xc6f4c8, 0x1126920}, {0xc000138000, 0x7, 0x7})
        /home/ber/go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:332 +0x566
github.com/urfave/cli/v2.(*App).Run(...)
        /home/ber/go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:309
main.main()
        /home/ber/go/pkg/mod/github.com/swaggo/swag/[email protected]/cmd/swag/main.go:341 +0x5d8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant