Skip to content

Commit f3ccea6

Browse files
author
Jay Conrod
authored
go/tools/builders: make subcommand errors less verbose (bazel-contrib#2664)
If a command fails, we'll just print the command path without its environment variables and arguments. Fixes bazel-contrib#2661
1 parent 64bfa14 commit f3ccea6

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

go/tools/builders/env.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,13 @@ func absEnv(envNameList []string, argList []string) error {
159159
}
160160

161161
func runAndLogCommand(cmd *exec.Cmd, verbose bool) error {
162-
formattedCmd := formatCommand(cmd)
163162
if verbose {
164-
os.Stderr.WriteString(formattedCmd)
163+
fmt.Fprintln(os.Stderr, formatCommand(cmd))
165164
}
166165
cleanup := passLongArgsInResponseFiles(cmd)
167166
defer cleanup()
168167
if err := cmd.Run(); err != nil {
169-
return fmt.Errorf("error running the following subcommand: %v\n%s", err, formattedCmd)
168+
return fmt.Errorf("error running subcommand %s: %v", cmd.Path, err)
170169
}
171170
return nil
172171
}
@@ -333,8 +332,8 @@ func absArgs(args []string, flags []string) {
333332
}
334333
}
335334

336-
// formatCommand writes cmd to w in a format where it can be pasted into a
337-
// shell. Spaces in environment variables and arguments are escaped as needed.
335+
// formatCommand formats cmd as a string that can be pasted into a shell.
336+
// Spaces in environment variables and arguments are escaped as needed.
338337
func formatCommand(cmd *exec.Cmd) string {
339338
quoteIfNeeded := func(s string) string {
340339
if strings.IndexByte(s, ' ') < 0 {
@@ -367,7 +366,6 @@ func formatCommand(cmd *exec.Cmd) string {
367366
fmt.Fprintf(&w, "%s%s", sep, quoteIfNeeded(arg))
368367
sep = " "
369368
}
370-
fmt.Fprint(&w, "\n")
371369
return w.String()
372370
}
373371

0 commit comments

Comments
 (0)