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
cmd/go: slightly confusing import cycle error when a package imports itself #23295
Comments
This attempt to sort out confusion about cyclical imports. In addition to the error message 'import cycle not allowed', we will now also give a specialized error for direct self-import, namely: self import not allowed Fixes golang#23295 Change-Id: I14e2418aa4eceb8caf2e6520c686fac7e85cb0dd
Change https://golang.org/cl/86536 mentions this issue: |
This attempt to sort out confusion about cyclical imports. In addition to the error message 'import cycle not allowed', we will now also give a specialized error for direct self-import, namely: self import not allowed Fixes golang#23295 Change-Id: I14e2418aa4eceb8caf2e6520c686fac7e85cb0dd
This change prevents import errors from being printed multiple times. Creating a bare-bones package `p` with only one file importing itself and running `go install p`, the current implementation gives this error message: ``` can't load package: import cycle not allowed package p imports p import cycle not allowed package p imports p ``` With this change we will show the message only once. Partially fixes golang#23295 Change-Id: I653b34c1c06c279f3df514f12ec0b89745a7e64a
Change https://golang.org/cl/86535 mentions this issue: |
This attempts to sort out confusion about cyclical imports. In addition to the error message "import cycle not allowed", for direct self imports we will now instead give a specialized error message, namely: self import not allowed Fixes golang#23295 Change-Id: I14e2418aa4eceb8caf2e6520c686fac7e85cb0dd
This attempts to sort out confusion about cyclical imports. In addition to the error message "import cycle not allowed", for direct self imports we will now instead give a specialized error message, namely: self import not allowed Fixes golang#23295 Change-Id: I14e2418aa4eceb8caf2e6520c686fac7e85cb0dd
This change prevents import errors from being printed multiple times. Creating a bare-bones package `p` with only one file importing itself and running `go install p`, the current implementation gives this error message: can't load package: import cycle not allowed package p imports p import cycle not allowed package p imports p With this change we will show the message only once. Partially fixes golang#23295 Change-Id: I653b34c1c06c279f3df514f12ec0b89745a7e64a
This change prevents import errors from being printed multiple times. Creating a bare-bones package `p` with only one file importing itself and running `go install p`, the current implementation gives this error message: can't load package: import cycle not allowed package p imports p import cycle not allowed package p imports p With this change we will show the message only once. Updates golang#23295 Change-Id: I653b34c1c06c279f3df514f12ec0b89745a7e64a
This attempts to sort out confusion about cyclical imports. In addition to the error message "import cycle not allowed", for direct self imports we will now instead give a specialized error message, namely: self import not allowed Fixes golang#23295 Change-Id: I14e2418aa4eceb8caf2e6520c686fac7e85cb0dd
This change prevents import errors from being printed multiple times. Creating a bare-bones package 'p' with only one file importing itself and running 'go build p', the current implementation gives this error message: can't load package: import cycle not allowed package p imports p import cycle not allowed package p imports p With this change we will show the message only once. Updates #23295 Change-Id: I653b34c1c06c279f3df514f12ec0b89745a7e64a Reviewed-on: https://go-review.googlesource.com/86535 Reviewed-by: Harald Nordgren <haraldnordgren@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This error is reported by go build/install, not the compiler. Reassigning. |
The doubled error message is fixed, but the remaining error is still awkward.
|
Do we care about GOPATH mode that much at this point? Module mode behaves better:
The double error is gone, but I still think the message could be more helpful to humans. For example, pointing at how a package can never import itself. But if we decide that that's unnecessary, I think the issue can be closed. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What did you do?
Create the package
p
in my GOPATH, with a single file, then rungo install
:What did you expect to see?
Some sort of error, like "a package cannot import itself".
What did you see instead?
This is a minimal example - I found this while merging package B into A, when B was importing A. This resulted in a couple of files in package A still importing package A.
I understand that the error is technically correct, but it's a bit confusing and it threw me off for a couple of seconds. The error message suggested above would have pointed me in the right direction faster.
It's also worth noting how the "import cycle not allowed" message is printed twice for some reason.
The text was updated successfully, but these errors were encountered: