From 9332d21c19199f99886b1476cab6f4dd89e82a72 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Wed, 10 Jul 2019 06:23:57 -0700 Subject: Unify command error handling BUG=chromium:773875 TEST=unit test Change-Id: Ibe32309c021d72e08cecc7d6830756fa1503e809 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1695801 Reviewed-by: Tobias Bosch Tested-by: Tobias Bosch --- compiler_wrapper/clang_tidy_flag.go | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'compiler_wrapper/clang_tidy_flag.go') diff --git a/compiler_wrapper/clang_tidy_flag.go b/compiler_wrapper/clang_tidy_flag.go index 9c1761ee..4a648ce1 100644 --- a/compiler_wrapper/clang_tidy_flag.go +++ b/compiler_wrapper/clang_tidy_flag.go @@ -73,18 +73,14 @@ func runClangTidy(env env, clangCmd *command, cSrcFile string) error { envUpdates: clangCmd.envUpdates, } - if err := env.run(clangTidyCmd, env.stdout(), env.stderr()); err != nil { - if _, ok := getExitCode(err); ok { - // Note: We continue on purpose when clang-tidy fails - // to maintain compatibility with the previous wrapper. - fmt.Fprintf(env.stderr(), "clang-tidy failed") - } else { - return wrapErrorwithSourceLocf(err, "failed to call clang tidy. Command: %#v", - clangTidyCmd) - } + exitCode, err := wrapSubprocessErrorWithSourceLoc(clangTidyCmd, + env.run(clangTidyCmd, env.stdout(), env.stderr())) + if err == nil && exitCode != 0 { + // Note: We continue on purpose when clang-tidy fails + // to maintain compatibility with the previous wrapper. + fmt.Fprintf(env.stderr(), "clang-tidy failed") } - - return nil + return err } func hasAtLeastOneSuffix(s string, suffixes []string) bool { -- cgit v1.2.3