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

Generating gqlgen using Go 1.24's go tool directive results in an error #3505

Closed
jamietanna opened this issue Jan 27, 2025 · 9 comments
Closed
Labels
help wanted Extra attention is needed

Comments

@jamietanna
Copy link

jamietanna commented Jan 27, 2025

When testing out the new go tool support in Go 1.24 (rc2), I've noticed that moving gqlgen from a tools.go type of ??, to the use of go tool results in an unhelpful error from go generate:

% go generate ./internal/graph
internal/graph/generate.go:3: running "go": exit status 1

When this fails, it also seems to delete the generated files:

 D internal/graph/generated.go
 D internal/graph/model/models_gen.go

It's unclear to me if this is an issue with gqlgen or with the Go toolchain itself. I've reported golang/go#71448 as it looks more likely due to the Go toolchain.

There is no additional insight given when using --verbose:

% go tool github.com/99designs/gqlgen generate --verbose
% echo $?
1

I have created a branch on one of my projects here to indicate the changes and help test:

Diff
diff --git go.mod go.mod
index f25db3d9..1c9ac1dd 100644
--- go.mod
+++ go.mod
@@ -1,8 +1,8 @@
 module dmd.tanna.dev

-go 1.22.7
+go 1.24

-toolchain go1.23.2
+toolchain go1.24rc2

 retract v1.0.0 // published accidentally

@@ -57,6 +57,7 @@ require (
 	github.com/cenkalti/backoff/v4 v4.3.0 // indirect
 	github.com/cespare/xxhash/v2 v2.3.0 // indirect
 	github.com/charmbracelet/lipgloss v0.10.0 // indirect
+	github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
 	github.com/dustin/go-humanize v1.0.1 // indirect
 	github.com/felixge/httpsnoop v1.0.4 // indirect
 	github.com/go-ini/ini v1.67.0 // indirect
@@ -89,12 +90,15 @@ require (
 	github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
 	github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
 	github.com/rivo/uniseg v0.4.7 // indirect
+	github.com/russross/blackfriday/v2 v2.1.0 // indirect
 	github.com/sirupsen/logrus v1.9.4-0.20230606125235-dd1b4c2e81af // indirect
 	github.com/sosodev/duration v1.3.1 // indirect
 	github.com/spf13/pflag v1.0.5 // indirect
 	github.com/tchap/go-patricia/v2 v2.3.1 // indirect
+	github.com/urfave/cli/v2 v2.27.2 // indirect
 	github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
 	github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
+	github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
 	github.com/yashtewari/glob-intersection v0.2.0 // indirect
 	go.opentelemetry.io/contrib/bridges/prometheus v0.57.0 // indirect
 	go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.8.0 // indirect
@@ -110,11 +114,13 @@ require (
 	go.opentelemetry.io/otel/metric v1.32.0 // indirect
 	go.opentelemetry.io/proto/otlp v1.3.1 // indirect
 	golang.org/x/exp v0.0.0-20231108232855-2478ac86f678 // indirect
+	golang.org/x/mod v0.18.0 // indirect
 	golang.org/x/net v0.30.0 // indirect
 	golang.org/x/oauth2 v0.23.0 // indirect
 	golang.org/x/sys v0.27.0 // indirect
 	golang.org/x/term v0.25.0 // indirect
 	golang.org/x/time v0.5.0 // indirect
+	golang.org/x/tools v0.22.0 // indirect
 	google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28 // indirect
 	google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 // indirect
 	google.golang.org/grpc v1.68.0 // indirect
@@ -128,3 +134,5 @@ require (
 	modernc.org/token v1.1.0 // indirect
 	sigs.k8s.io/yaml v1.4.0 // indirect
 )
+
+tool github.com/99designs/gqlgen
diff --git go.sum go.sum
index 77eec844..2391fcf0 100644
--- go.sum
+++ go.sum
@@ -50,6 +50,7 @@ github.com/charmbracelet/lipgloss v0.10.0 h1:KWeXFSexGcfahHX+54URiZGkBFazf70JNMt
 github.com/charmbracelet/lipgloss v0.10.0/go.mod h1:Wig9DSfvANsxqkRsqj6x87irdy123SR4dOXlKa91ciE=
 github.com/charmbracelet/log v0.4.0 h1:G9bQAcx8rWA2T3pWvx7YtPTPwgqpk7D68BX21IRW8ZM=
 github.com/charmbracelet/log v0.4.0/go.mod h1:63bXt/djrizTec0l11H20t8FDSvA4CRZJ1KH22MdptM=
+github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
 github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -193,6 +194,7 @@ github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
 github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
 github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
 github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
+github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
 github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
 github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
 github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
@@ -228,6 +230,8 @@ github.com/terminalstatic/go-xsd-validate v0.1.5 h1:RqpJnf6HGE2CB/lZB1A8BYguk8uR
 github.com/terminalstatic/go-xsd-validate v0.1.5/go.mod h1:18lsvYFofBflqCrvo1umpABZ99+GneNTw2kEEc8UPJw=
 github.com/uluyol/prefixwriter v1.0.0 h1:gI5Y7bvKYxjPy/981t7cdLmosM7azibUnXqztrU/PlY=
 github.com/uluyol/prefixwriter v1.0.0/go.mod h1:ESIgj7im/hMimsEgVYM36iWSG2zFdRm/Qp9xgkVrzL8=
+github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI=
+github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM=
 github.com/vektah/gqlparser/v2 v2.5.16 h1:1gcmLTvs3JLKXckwCwlUagVn/IlV2bwqle0vJ0vy5p8=
 github.com/vektah/gqlparser/v2 v2.5.16/go.mod h1:1lz1OeCqgQbQepsGxPVywrjdBHW2T08PUS3pJqepRww=
 github.com/xanzy/go-gitlab v0.106.0 h1:EDfD03K74cIlQo2EducfiupVrip+Oj02bq9ofw5F8sA=
@@ -238,6 +242,8 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHo
 github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
 github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
 github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
+github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw=
+github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913/go.mod h1:4aEEwZQutDLsQv2Deui4iYQ6DWTxR14g6m8Wv88+Xqk=
 github.com/yashtewari/glob-intersection v0.2.0 h1:8iuHdN88yYuCzCdjt0gDe+6bAhUwBeEWqThExu54RFg=
 github.com/yashtewari/glob-intersection v0.2.0/go.mod h1:LK7pIC3piUjovexikBbJ26Yml7g8xa5bsjfx2v1fwok=
 gitlab.com/tanna.dev/cobra-doc-template v0.0.0-20231221133114-8f5f0e77db94 h1:E/a08cCN6FdD3kTajcpEEPRvafmjfFMvhgVv0zjtIq4=
diff --git internal/graph/generate.go internal/graph/generate.go
index 3a55bcdb..763d172a 100644
--- internal/graph/generate.go
+++ internal/graph/generate.go
@@ -1,3 +1,3 @@
 package graph

-//go:generate go run -modfile=../../tools/go.mod github.com/99designs/gqlgen generate
+//go:generate go tool github.com/99designs/gqlgen generate
@jamietanna
Copy link
Author

Via golang/go#71448 (comment) it looks like it may need a bump of /x/tools

@alexandear
Copy link
Contributor

There is already PR #3483 for bumping x/tools.

@thepudds
Copy link

thepudds commented Feb 3, 2025

results in an unhelpful error from go generate:

% go generate ./internal/graph
internal/graph/generate.go:3: running "go": exit status 1

Hi @jamietanna, is it clear what the full error message is, and/or is it possible to modify the user code to dump more of the error, or dump stderr/stdout, or otherwise see more detail?

In theory, x/tools should give a good error message if it can't continue because it's not new enough, and it would be good to see if that's happening here.

Some background is that for many years, there have been a series of semi-cryptic messages from x/tools when some community tool was using a too-old version of x/tools, such as:

internal error: package "fmt" without types was imported from "github.com/some/mod"
exit status 1

... where that error did not even mention x/tools or x/tools/go/packages.

I think that particular cryptic error message was eventually addressed (I'd have to check again to see what change, but maybe golang/tools@edddc5f or similar). Part of the reason the unhelpful messages lingered for years was because the workaround was just to update x/tools and things started working again.... but then 6 or 12 months later, there would be a new round of reports after a subsequent Go release.

If there is some new unhelpful error or a reoccurrence of a prior unhelpful error, it would be good to get it resolved in x/tools.

Alternatively, if there is a good error from x/tools in this example and it's just that gqlgen is not reporting the full error, it might save some headache in the future for gqlgen to report that error.

@StevenACoffman StevenACoffman added the help wanted Extra attention is needed label Feb 10, 2025
@StevenACoffman
Copy link
Collaborator

@thepudds If x/tools always gives a cryptic error when it is out of date, that is a chicken and egg problem for gqlgen. gqlgen can never stay on bleeding edge x/tools since it always needs to support trailing edge Go versions. (obsoleting edge/lagging edge/trailing edge? Not sure what the term is.)

For background, at my day job, we use GCP AppEngine, which always lags by only supporting the oldest possible Go version (and sometimes even older ಠ_ಠ ). Currently GCP AppEngine has GA support only for Go 1.22. While I do almost all of my gqlgen maintenance outside of my day job, their real-world complicated usage lets me find edge cases in gqlgen that I otherwise never would, and they also rely on gqlgen and I rely on them to eat.

@jamietanna Sorry, I just noticed this issue! Your stuff is always brilliant and has made my life better. If I can help you in any way, always ping me and let me know.

@StevenACoffman
Copy link
Collaborator

StevenACoffman commented Feb 10, 2025

@jamietanna Sorry for any notification spam, but just to link all the things together, the draft PR is here: #3528

Your project issue I opened is here:
https://gitlab.com/tanna.dev/dependency-management-data/-/issues/643

And you (or anyone with a similar problem) can try gqlgen with temporary updated x/tools out using:

go mod edit -replace github.com/99designs/gqlgen=github.com/99designs/gqlgen@a3dcd48596adbbba527c0d01bbcf78056e25783e
go mod tidy

@UnAfraid
Copy link
Contributor

UnAfraid commented Feb 13, 2025

I just updated one of my projects to go 1.24 and i didn't encounter any problems, even using the new go tool directive and command for gqlgen
UnAfraid/wg-ui@aa957ae

likid1412 added a commit to likid1412/gqlgen-todos that referenced this issue Feb 14, 2025
@StevenACoffman
Copy link
Collaborator

Please see #3537

@StevenACoffman
Copy link
Collaborator

Hey folks, I think this is "fixed" #3537 as I was able to find golang.org/x/[email protected] version that would work with both Go 1.24, Go 1.23, and Go 1.22. I have cut a release including this in v0.17.65 so it can unblock people if this solves their issues.

The dependabot upgrades to x/[email protected] had previously been failing tests here with Go 1.22 with that same old x/tools version, so the fact that it is working now means it may be possible to update x/tools even further (the x/tools go.mod still says Go 1.22 in several newer releases).

However, #3532 reports seeing minor differences in exec.go when run under Go 1.23 and Go 1.24 which cause consistency issues in CI/CDD.

The new testing matrix includes Go 1.22, Go 1.23, Go 1.24 so I'm not able to reproduce that problem here (or in my day job stuff), so I would be very grateful for you to report any other issues you find.

@likid1412 @jamietanna @UnAfraid @alexandear FYI

@StevenACoffman
Copy link
Collaborator

Ok, I'm a doofus. Dependabot threw errors for x/tools upgrades for anything after Go 1.23, but they were trivial to resolve by just also applying them to the _examples and running go mod tidy.

I updated x/tools to latest and cut v0.17.66

Please report any minor differences in exec.go in #3532

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants