Skip to content

Commit d7185a9

Browse files
matthijskooijmanfacchinm
authored andcommitted
Do not ignore command errors in ExecRecipeCollectStdErr
Previously, this function would ignore any errors returned by `Run()` since the command is expected to fail in most cases. However, in addition to ignoring a non-zero exit code from the command, it would also ignore errors in running the command itself. With this commit, `ExecRecipeCollectStdErr()` simply returns all errors, but its caller checks the type of the error. If it is `ExitError`, this indicates a non-zero exit status, which is ignored. Otherwise, the error is reported as normal. Signed-off-by: Matthijs Kooijman <[email protected]>
1 parent cabf30a commit d7185a9

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

Diff for: builder_utils/utils.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,8 @@ func ExecRecipeCollectStdErr(buildProperties properties.Map, recipe string, remo
459459

460460
buffer := &bytes.Buffer{}
461461
command.Stderr = buffer
462-
command.Run()
463-
return string(buffer.Bytes()), nil
462+
err = command.Run()
463+
return string(buffer.Bytes()), err
464464
}
465465

466466
func RemoveHyphenMDDFlagFromGCCCommandLine(buildProperties properties.Map) {

Diff for: container_find_includes.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ import (
110110
"encoding/json"
111111
"io/ioutil"
112112
"os"
113+
"os/exec"
113114
"path/filepath"
114115
"time"
115116

@@ -324,7 +325,12 @@ func findIncludesUntilDone(ctx *types.Context, cache *includeCache, sourceFile t
324325
}
325326
} else {
326327
stderr, err := GCCPreprocRunnerForDiscoveringIncludes(ctx, sourcePath, targetFilePath, includes)
327-
if err != nil {
328+
// Unwrap error and see if it is an ExitError.
329+
// Ignore ExitErrors (e.g. gcc returning
330+
// non-zero status), but bail out on other
331+
// errors
332+
_, is_exit_error := i18n.UnwrapError(err).(*exec.ExitError)
333+
if err != nil && !is_exit_error {
328334
return i18n.WrapError(err)
329335
}
330336
include = IncludesFinderWithRegExp(ctx, stderr)

Diff for: gcc_preproc_runner.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func GCCPreprocRunnerForDiscoveringIncludes(ctx *types.Context, sourceFilePath s
7777

7878
stderr, err := builder_utils.ExecRecipeCollectStdErr(properties, constants.RECIPE_PREPROC_MACROS, true, verbose, verbose, logger)
7979
if err != nil {
80-
return "", i18n.WrapError(err)
80+
return string(stderr), i18n.WrapError(err)
8181
}
8282

8383
return string(stderr), nil

Diff for: i18n/errors.go

+11
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,14 @@ func WrapError(err error) error {
1818
}
1919
return errors.Wrap(err, 0)
2020
}
21+
22+
func UnwrapError(err error) error {
23+
// Perhaps go-errors can do this already in later versions?
24+
// See https://github.com/go-errors/errors/issues/14
25+
switch e := err.(type) {
26+
case *errors.Error:
27+
return e.Err
28+
default:
29+
return err
30+
}
31+
}

0 commit comments

Comments
 (0)