Skip to content

cmd/go: helpful error messages when hg, git, svn, bzr not found #4652

@bradfitz

Description

@bradfitz
If a vcs tool like hg, git, svn, bzr is not found, cmd/go should explain to the user
what to install.

See confusion at https://plus.google.com/u/0/115056313943520401920/posts/Xvmwe76BJMS

vcs.go currently has just:

// run1 is the generalized implementation of run and runOutput.                         
                                                                                        
                                   
func (v *vcsCmd) run1(dir string, cmdline string, keyval []string, verbose bool)
([]byte, error) {
        m := make(map[string]string)
        for i := 0; i < len(keyval); i += 2 {
                m[keyval[i]] = keyval[i+1]
        }
        args := strings.Fields(cmdline)
    for i, arg := range args {
                args[i] = expand(m, arg)
        }

        cmd := exec.Command(v.cmd, args...)
        cmd.Dir = dir
        if buildX {
                fmt.Printf("cd %s\n", dir)
        fmt.Printf("%s %s\n", v.cmd, strings.Join(args, " "))
        }
        var buf bytes.Buffer
        cmd.Stdout = &buf
    cmd.Stderr = &buf
        err := cmd.Run()
        out := buf.Bytes()
        if err != nil {
                if verbose || buildV {
                        fmt.Fprintf(os.Stderr, "# cd %s; %s %s\n", dir, v.cmd, strings.Join(args, " "))
                        os.Stderr.Write(out)
        }
                return nil, err
        }
        return out, nil
}

We are more helpful in at at least one other case, as precedent:

        if toolIsWindows && toolName == "pprof" {
            args = append([]string{"perl", toolPath}, args[1:]...)
            var err error
                toolPath, err = exec.LookPath("perl")
                if err != nil {
                        fmt.Fprintf(os.Stderr, "go tool: perl not found\n")
                        setExitStatus(3)
            return
                }
        }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions