-
Notifications
You must be signed in to change notification settings - Fork 18k
x/tools/cmd/stringer: does no longer work in package with uninstalled dependencies #31216
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
Comments
I'm sorry, I don't completely understand: what do you mean by uninstalled dependencies? Do you mean that the dependencies of the package itself are missing? |
@matloob Yes, by that I mean packages that I import in my project but are actually not installed on the system. This happens i.e. when building a Docker image for a Go project that uses stringer.
Using This might be a edge case but I thought that pointing out that it used to work and now it doesn't was the right thing to do. |
To reproduce:
It seems like running stringer the first time makes it crash but running it again works correctly. |
It looks like the bug first appears in golang/tools@dbeab5a |
Hm, this is interesting:
I don't think go list should have that behavior. Though we'll need to put in a temporary fix for the mean time edit: added "-e", though the behavior is present both with and without -e |
I want to make sure I understand the problem: You're trying to run stringer on a package that has a dependency that doesn't exist right? I'm going to do some research to figure out how stringer handles packages it can't type-check. |
@bcmills @jayconrod for the go list behavior in #31216 (comment). Is that expected? |
@matloob It's correct. In my example I've used a meaningless string for the package name (you can also use completely random strings that don't make any sense for the import path actually and the issue remains) while in my real world scenario I was dealing with real libraries (such as logrus) that were imported but were not installed on the system yet |
Are you using a meaningless string so you can replicate after the first time you stringer? That is, were you also seeing the issue when using a package that does exist? I think the go list behavior in the comment above explains the behavior with a package that doesn't exist, but if it's happening with a package that does exist, there's another, bigger problem. Could you try running stringer with a empty GOCACHE and GOPATH as follows?:
I'm interested if you still see the error in that case |
@bcmills, so go list -e should return a zero exit status even if an imported package doesn't exist, right? I'll have go/packages suppress that particular error |
@matloob So I originally discovered the issue while using packages that exist and can be fetched (such as By the way yes I used random strings to find the commit that first caused the bug. The fact that stringer sometimes starts working from the second time on could be related to the choice of the import path (existing but not installed, existing but potentially valid or completely random). I'll investigate on that. Also I'll try what you suggested EDIT: I've never observed stringer failing when all imported packages were installed. I've seen it fail when using an import string that satisfies one of these:
|
Okay, thanks! Looking forward to the results |
I think the first lines should be ignore as go mod is trying to fetch the dependency but the installed stringer version is still the one from golang/tools@dbeab5a The issue doesn't resolve itself by running the command twice. |
Okay, that matches what I saw on my own machine. I'm wondering if you can get a reproduction with a package that does exist? |
Okay so reproducing the error with existing packages is much more difficult than I thought. I might have oversimplified some of my examples and I'm very sorry for that :( Basically I am not using go modules and I have a subpackage that has no go files until code generation is run. This package (once generated) will depend on an external package (github.com/sirupsen/logrus) this is very important, otherwise stringer will just work based on my experiments. Running go generate will run code generation for the subpackage (a trival file renaming) and also stringer for the root package. This is the (rather weird maybe but no that much) scenario where stringer fails. You can see below that (in this scenario) stringer only fails when using dbeab5a or later
|
Hi I'm really sorry this fell through the cracks. I tried reproducing it (using head) and I got now errors for both attempts (at head and at 45dd101). Is this still an issue? |
No worries. Actually I'm not having issues anymore on the latest version with my current project setup |
Ok, I'll mark this as closed then. Please reopen if this shows up again. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Ran
stringer -type MyType
in the package where structMyType
is declared.What did you expect to see?
stringer running correctly and producing a generated code file like it always did so far
What did you see instead?
This error
It seems like stringer is no longer able to operate when searching for a type declaration in a package that has uninstalled dependencies like it did before.
Installing dependencies before running stringer makes it work correctly.
Why would anyone need this?
I'm building docker images for my go application that doesn't use any dependency managment tool yet. The build process:
go generate
go get -d ./...
. Because of this there's no need to update the Dockerfile after adding or removing dependencies.Running
go generate
beforego get -d ./...
is necessary because otherwise some directories would end up having no go files, causing go get to fail.When was it working?
I've manually installed a version of
golang.org/x/tools
that goes back to the first week of march 2019 and that one works without any problems. It seems likegolang.org/x/tools/go/packages
has been updated ever since (whilegolang.org/x/tools/cmd/stringer
hasn't) but I can't pinpoint the line or commit that is causing the issue.Maybe this is even some intentional behaviour?
The text was updated successfully, but these errors were encountered: