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

Open
mvdan opened this Issue Jan 1, 2018 · 4 comments

Comments

Projects
None yet
6 participants
@mvdan
Member

mvdan commented Jan 1, 2018

What version of Go are you using (go version)?

go version devel +f3f507b2d8 Fri Dec 22 21:13:38 2017 +0000 linux/amd64

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 run go install:

package p

import "p"

What did you expect to see?

Some sort of error, like "a package cannot import itself".

What did you see instead?

$ go install
can't load package: import cycle not allowed
package p
        imports p
import cycle not allowed
package p
        imports p

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.

HaraldNordgren added a commit to HaraldNordgren/go that referenced this issue Jan 7, 2018

load: special error message for direct self-import
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
@gopherbot

This comment has been minimized.

gopherbot commented Jan 7, 2018

Change https://golang.org/cl/86536 mentions this issue: load: special error message for direct self-import

HaraldNordgren added a commit to HaraldNordgren/go that referenced this issue Jan 7, 2018

cmd/go: special error message for direct self-import
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

HaraldNordgren added a commit to HaraldNordgren/go that referenced this issue Jan 7, 2018

cmd/go: print each import error only once
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
@gopherbot

This comment has been minimized.

gopherbot commented Jan 7, 2018

Change https://golang.org/cl/86535 mentions this issue: cmd/go: print each import error only once

HaraldNordgren added a commit to HaraldNordgren/go that referenced this issue Jan 7, 2018

cmd/go: special error message for direct self import
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

HaraldNordgren added a commit to HaraldNordgren/go that referenced this issue Jan 7, 2018

cmd/go: special error message for direct self import
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

HaraldNordgren added a commit to HaraldNordgren/go that referenced this issue Jan 7, 2018

cmd/go: print each import error only once
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

HaraldNordgren added a commit to HaraldNordgren/go that referenced this issue Jan 7, 2018

cmd/go: print each import error only once
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

HaraldNordgren added a commit to HaraldNordgren/go that referenced this issue Jan 7, 2018

cmd/go: special error message for direct self import
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

@griesemer griesemer added this to the Go1.11 milestone Jan 11, 2018

gopherbot pushed a commit that referenced this issue Mar 27, 2018

cmd/go: print each import error only once
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>
@griesemer

This comment has been minimized.

Contributor

griesemer commented Jun 5, 2018

This error is reported by go build/install, not the compiler. Reassigning.

@griesemer griesemer changed the title from cmd/compile: slightly confusing import cycle error when a package imports itself to cmd/go: slightly confusing import cycle error when a package imports itself Jun 5, 2018

@griesemer griesemer assigned rsc and unassigned mdempsky and griesemer Jun 5, 2018

@griesemer griesemer modified the milestones: Go1.11, Go1.12 Jun 5, 2018

@bcmills

This comment has been minimized.

Member

bcmills commented Nov 15, 2018

The doubled error message is fixed, but the remaining error is still awkward.

gopath$ mkdir p
gopath$ cd p
gopath/p$ cat >> p.go
package p
import "p"

gopath/p$ GO111MODULE=off go install
p.go:2:8: cannot find package "p" in any of:
        /home/bcmills/go/src/p (from $GOROOT)
        /tmp/tmp.aMjUpuxIN7/gopath/src/p (from $GOPATH)

@bcmills bcmills added the NeedsFix label Nov 15, 2018

@bcmills bcmills modified the milestones: Go1.12, Go1.13 Nov 15, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment