fix: problem detecting stdlib modules when using toolchains - #329
Open
adamconnelly wants to merge 1 commit into
Open
fix: problem detecting stdlib modules when using toolchains#329adamconnelly wants to merge 1 commit into
adamconnelly wants to merge 1 commit into
Conversation
If the pkg.Module is `nil`, it's either part of the stdlib or it's not something that go-licenses can analyze correctly. Let's just skip modules like this instead of reporting an error. The problem with the existing check is that it assumes that stdlib packages will have source files under `build.Default.GOROOT`. But if the module you're trying to analyze has a `toolchain` directive in its go.mod file that differs from the version of Go installed, the package will have a path outside of this directory.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
FranLegon
approved these changes
Apr 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If the pkg.Module is
nil, it's either part of the stdlib or it's not something that go-licenses can analyze correctly. Let's just skip modules like this instead of reporting an error.The problem with the existing check is that it assumes that stdlib packages will have source files under
build.Default.GOROOT. But if the module you're trying to analyze has atoolchaindirective in its go.mod file that differs from the version of Go installed, the package will have a path outside of this directory.I think we could possibly also remove the code that checks for a specific prefix based off the GOROOT, but I wasn't 100% sure of that so I've left it in for now. I figure it doesn't do any harm (other than add a bit of confusion for future potentially).
Reproducing the problem is pretty simple:
toolchain <go-version>directive in the go.mod file where that version is different to your installed Go version (e.g. 1.24.2).The crossplane project referenced in #302 actually has an example of this in their go.mod file (presumably the cause of the problem).
I think this should resolve the following issues:
go 1.21.X#244.go 1.N.Pgo.mod syntax #324.