Skip to content
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

gomod failed to retrieve modules. #115

Closed
alexeykiselev opened this issue Jul 8, 2021 · 3 comments · Fixed by #116
Closed

gomod failed to retrieve modules. #115

alexeykiselev opened this issue Jul 8, 2021 · 3 comments · Fixed by #116
Labels
bug Something isn't working

Comments

@alexeykiselev
Copy link

OS: macOS 10.15.7

❯ go version
go version go1.16.5 darwin/amd64

I've tried gomod version 0.7.0 and latest master.

On attempt to analyse a project the error occurred:

❯ gomod analyse -v
17:11:16 debug graph Creating dependency graph.
17:11:16 debug modinfo Ensuring module information is available locally by running 'go mod download'.
17:11:16 debug modinfo Running command. {"args": ["/usr/local/bin/go", "go", "mod", "download"]}
17:11:16 debug modinfo Finished running. {"args": ["/usr/local/bin/go", "go", "mod", "download"], "stdout": "", "stderr": ""}
17:11:16 debug modinfo Retrieving module information via 'go list'
17:11:16 debug modinfo Running command. {"args": ["/usr/local/bin/go", "go", "list", "-json", "-m", "all"]}
go list -m: can't compute 'all' using the vendor directory
	(Use -mod=mod or -mod=readonly to bypass.)
17:11:16 debug modinfo Finished running. {"args": ["/usr/local/bin/go", "go", "list", "-json", "-m", "all"], "stdout": "", "stderr": "go list -m: can't compute 'all' using the vendor directory\n\t(Use -mod=mod or -mod=readonly to bypass.)\n"}
17:11:16 error modinfo Command exited with an error. {"args": ["/usr/local/bin/go", "go", "list", "-json", "-m", "all"], "error": "exit status 1"}
17:11:16 error modinfo Failed to list modules in dependency graph via 'go list'. {"error": "failed to run 'go list -json -m all: exit status 1"}
Error: failed to run 'go list -json -m all: exit status 1
Usage:
  gomod analyse [flags]

Aliases:
  analyse, analyze

Flags:
  -h, --help   help for analyse

Global Flags:
  -v, --verbose strings[=all]   Verbose output. See 'gomod --help' for more information.

17:11:16 debug all Exited with an error. {"error": "failed to run 'go list -json -m all: exit status 1"}

Adding suggested option-mod=mod to arguments list at internal/modules/modules.go:81 and internal/depgraph/deps_pkg.go:146 solves the problem.

diff --git a/internal/depgraph/deps_pkg.go b/internal/depgraph/deps_pkg.go
index 0caed4a..cac4cf8 100644
--- a/internal/depgraph/deps_pkg.go
+++ b/internal/depgraph/deps_pkg.go
@@ -143,7 +143,7 @@ func (g *DepGraph) retrieveTransitiveImports(log *logger.Logger, pkgs []string)
 }
 
 func (g *DepGraph) retrievePackageInfo(log *logger.Logger, pkgs []string) (imports []string, err error) {
-	stdout, _, err := util.RunCommand(log, g.Main.Info.Dir, "go", append([]string{"list", "-json"}, pkgs...)...)
+	stdout, _, err := util.RunCommand(log, g.Main.Info.Dir, "go", append([]string{"list", "-mod=mod", "-json"}, pkgs...)...)
 	if err != nil {
 		log.Error("Failed to list imports for packages.", zap.Strings("packages", pkgs), zap.Error(err))
 		return nil, err
diff --git a/internal/modules/modules.go b/internal/modules/modules.go
index 6080c91..757063b 100644
--- a/internal/modules/modules.go
+++ b/internal/modules/modules.go
@@ -78,7 +78,7 @@ func retrieveModuleInformation(
 	}
 
 	log.Debug("Retrieving module information via 'go list'")
-	goListArgs := append([]string{"list", "-json", "-m"}, extraGoListArgs...)
+	goListArgs := append([]string{"list", "-mod=mod", "-json", "-m"}, extraGoListArgs...)
 	if targetModule == "" {
 		targetModule = "all"
 	}
@alexeykiselev alexeykiselev added the bug Something isn't working label Jul 8, 2021
@Helcaraxan
Copy link
Owner

Hello @alexeykiselev. Thank you for the report, and a solution with it nonetheless! gomod had indeed not yet been tested on projects using vendoring and this is why this bug had slipped through.

I will use your solution as is as it entirely makes sense. 👍

@Helcaraxan
Copy link
Owner

I have just pushed the 0.7.1 release which contains the fix for this bug. 🙂

@alexeykiselev
Copy link
Author

Hello @Helcaraxan! I've tested the latest release, everything works fine! Good luck with your project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants