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: Import cycle build error can be more helpful #12871

Open
willfaught opened this Issue Oct 7, 2015 · 5 comments

Comments

Projects
None yet
3 participants
@willfaught
Contributor

willfaught commented Oct 7, 2015

The error can be more helpful if it pinpoints the files/lines that cause the cycle.

Example:

$ go build
can't load package: import cycle not allowed
package foo
    imports foo
import cycle not allowed
package foo
    imports foo

That could be anywhere in foo.

@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented Oct 7, 2015

I think it's a fine idea, but the cycle can't be anywhere in foo: it has to be an import statement, and import statements have to be near the start of a file.

@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Oct 7, 2015

@willfaught

This comment has been minimized.

Contributor

willfaught commented Oct 8, 2015

Yes, but it could be in any file.

@willfaught

This comment has been minimized.

Contributor

willfaught commented Oct 14, 2015

Also, I don't understand why it prints the message and cycle twice.

@VojtechVitek

This comment has been minimized.

VojtechVitek commented Nov 9, 2016

@ianlancetaylor

It be nice to have file:line in the error message.

Instead of

import cycle not allowed
package github.com/pressly/api/cmd/api
        imports github.com/pressly/api
        imports github.com/pressly/api/data
        imports github.com/pressly/api/data/presenter
        imports github.com/pressly/api/data

I'd propose

import cycle not allowed
package github.com/pressly/api/cmd/api
        imports github.com/pressly/api
                at cmd/main.go:12
        imports github.com/pressly/api/data
                at api.go:8
        imports github.com/pressly/api/data/presenter
                at data/user.go:14
        imports github.com/pressly/api/data
                at data/presenter/user.go:6

I can implement this if you guys like the idea.

@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented Nov 9, 2016

Sure, though I would keep it on line ("imports github.com/pressly/api at cmd/main.go:12"). It's too late for Go 1.8 but please send a CL for Go 1.9.

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