Khan / genqlient

a truly type-safe Go GraphQL client
MIT License
1.07k stars 107 forks source link

panic: runtime error: invalid memory address -- generate.go:403 #288

Closed gcsfred2 closed 8 months ago

gcsfred2 commented 1 year ago

Describe the bug

$go run github.com/Khan/genqlient
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x10064243c]

goroutine 1 [running]:
go/printer.(*printer).intersperseComments(0x1409d2a11a0, {{0x0, 0x0}, 0x4000011c, 0x728efe, 0x1af}, 0x50)
    /usr/local/go/src/go/printer/printer.go:741 +0x9c
go/printer.(*printer).flush(0x1409d2a0dc8?, {{0x0, 0x0}, 0x4000011c, 0x728efe, 0x1af}, 0x0?)
    /usr/local/go/src/go/printer/printer.go:1044 +0x80
go/printer.(*printer).print(0x1409d2a11a0, {0x1409d2a0f20?, 0x1, 0x0?})
    /usr/local/go/src/go/printer/printer.go:1005 +0x510
go/printer.(*printer).stmt(0x1409d2a11a0, {0x1008bd408, 0x140f2a30980}, 0x0)
    /usr/local/go/src/go/printer/nodes.go:1373 +0x1614
go/printer.(*printer).printNode(0x1409d2a11a0, {0x100876c20?, 0x140f2a30980?})
    /usr/local/go/src/go/printer/printer.go:1159 +0x3d4
go/printer.(*Config).fprint(0x1409d2a1380, {0x1008bb0b8?, 0x141f4925980}, 0x1409d2a1960?, {0x100876c20, 0x140f2a30980}, 0x1411f130780)
    /usr/local/go/src/go/printer/printer.go:1332 +0x100
go/printer.(*printer).nodeSize(0x1409d2a1960, {0x1008bc768?, 0x140f2a30980}, 0x64)
    /usr/local/go/src/go/printer/nodes.go:1744 +0xe8
go/printer.(*printer).bodySize(0x1409d2a1960, 0x140f2a2db30, 0x64)
    /usr/local/go/src/go/printer/nodes.go:1791 +0x264
go/printer.(*printer).funcBody(0x1409d2a1960, 0x1ac, 0xb, 0x140f2a2db30)
    /usr/local/go/src/go/printer/nodes.go:1813 +0x94
go/printer.(*printer).funcDecl(0x1409d2a1960, 0x140f2a2db60)
    /usr/local/go/src/go/printer/nodes.go:1858 +0x16c
go/printer.(*printer).decl(0x1409d2a1960?, {0x1008bd0d8?, 0x140f2a2db60?})
    /usr/local/go/src/go/printer/nodes.go:1868 +0xf0
go/printer.(*printer).declList(0x1409d2a1960, {0x140fca80000?, 0x22e6d0, 0x0?})
    /usr/local/go/src/go/printer/nodes.go:1911 +0x460
go/printer.(*printer).file(0x1409d2a5960?, 0x1411dd98f80)
    /usr/local/go/src/go/printer/nodes.go:1919 +0xf0
go/printer.(*printer).printNode(0x1409d2a5960, {0x100871440?, 0x1411dd98f80?})
    /usr/local/go/src/go/printer/printer.go:1176 +0x4e8
go/printer.(*Config).fprint(0x1409d2a1c10, {0x1008bb0b8?, 0x1411f130750}, 0xa6?, {0x100871440, 0x1411dd98f80}, 0x1411f130780)
    /usr/local/go/src/go/printer/printer.go:1332 +0x100
go/printer.(*Config).Fprint(...)
    /usr/local/go/src/go/printer/printer.go:1392
go/format.format(0x1404a0ddaa0?, 0x1411dd98f80?, 0x0?, 0x141747ce000?, {0x141747ce000?, 0x0?, 0x1?}, {0x40000006, 0x8, 0x0})
    /usr/local/go/src/go/format/internal.go:105 +0x80
go/format.Source({0x141747ce000, 0x4cd86642, 0x4cd88000})
    /usr/local/go/src/go/format/format.go:114 +0xb8
github.com/Khan/genqlient/generate.Generate(0x140001602c0)
    /Users/gf/go/pkg/mod/github.com/!khan/genqlient@v0.5.0/generate/generate.go:403 +0x54c
github.com/Khan/genqlient/generate.readConfigGenerateAndWrite({0x0?, 0x14000028000?})
    /Users/gf/go/pkg/mod/github.com/!khan/genqlient@v0.5.0/generate/main.go:30 +0x50
github.com/Khan/genqlient/generate.Main()
    /Users/gf/go/pkg/mod/github.com/!khan/genqlient@v0.5.0/generate/main.go:86 +0xbc
main.main()
    /Users/gf/go/pkg/mod/github.com/!khan/genqlient@v0.5.0/main.go:14 +0x1c
exit status 2

The error above happened after running for about 14 hours.

To Reproduce The problem happens at code-generation time.

Expected behavior No exception.

genqlient version genqlient@v0.5.0

Additional context

benjaminjkraft commented 1 year ago

Thanks for the report! Can you give a repro -- your schema, queries, genqlient.yaml (or, ideally, a minimal set of the same that reproduces the issue)? If you're unable to share that, I think you'll have to do some more debugging yourself -- it looks like it's the gofmt that's failing so I'd suggest changing generate.go to print out the source before and see if you can see what's wrong. Perhaps this is a gofmt bug, in fact -- you would think it should, at worst, simply reject the code and not panic!

gcsfred2 commented 1 year ago

genqlient.yaml: https://pastebin.com/0Wb2Mjkx password LH2UDPAH4H3x schema.graphql: https://pastebin.com/5kCv6Et3 password ASzHn7q7sS

benjaminjkraft commented 1 year ago

Thanks -- you'll also need to share the queries you used! And your go version will also be useful, since I suspect this issue is in part a gofmt issue.

benjaminjkraft commented 8 months ago

Closing this issue, we can reopen if we get the additional info!