From 9146f003426d55ce13f5704ee4bb3bde15f4aef5 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Sat, 2 May 2020 17:32:37 -0600 Subject: [PATCH] Minor improvements; print go list errors, strip trailing slashes --- builder.go | 2 +- cmd/xcaddy/main.go | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/builder.go b/builder.go index 8064084..a235d7f 100644 --- a/builder.go +++ b/builder.go @@ -73,7 +73,7 @@ func (b Builder) Build(ctx context.Context, outputFile string) error { } defer buildEnv.Close() - // prepare the environmen for the go command; for + // prepare the environment for the go command; for // the most part we want it to inherit our current // environment, with a few customizations env := os.Environ() diff --git a/cmd/xcaddy/main.go b/cmd/xcaddy/main.go index 404eb65..c970d09 100644 --- a/cmd/xcaddy/main.go +++ b/cmd/xcaddy/main.go @@ -63,6 +63,7 @@ func runBuild(ctx context.Context, args []string) error { if err != nil { return err } + mod = strings.TrimSuffix(mod, "/") // easy to accidentally leave a trailing slash if pasting from a URL, but is invalid for Go modules plugins = append(plugins, xcaddy.Dependency{ ModulePath: mod, Version: ver, @@ -136,17 +137,19 @@ func runDev(ctx context.Context, args []string) error { // get current/main module name cmd := exec.Command("go", "list", "-m") + cmd.Stderr = os.Stderr out, err := cmd.Output() if err != nil { - return err + return fmt.Errorf("exec %v: %v: %s", cmd.Args, err, string(out)) } currentModule := strings.TrimSpace(string(out)) // get the root directory of the main module cmd = exec.Command("go", "list", "-m", "-f={{.Dir}}") + cmd.Stderr = os.Stderr out, err = cmd.Output() if err != nil { - return err + return fmt.Errorf("exec %v: %v: %s", cmd.Args, err, string(out)) } moduleDir := strings.TrimSpace(string(out)) @@ -164,9 +167,10 @@ func runDev(ctx context.Context, args []string) error { // go.mod, we need to transfer their replace directives through // to the one we're making cmd = exec.Command("go", "list", "-m", "-f={{if .Replace}}{{.Path}} => {{.Replace}}{{end}}", "all") + cmd.Stderr = os.Stderr out, err = cmd.Output() if err != nil { - return err + return fmt.Errorf("exec %v: %v: %s", cmd.Args, err, string(out)) } for _, line := range strings.Split(string(out), "\n") { parts := strings.Split(line, "=>")