aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/cpp/util/errors.cc
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2017-02-15 18:07:29 +0000
committerGravatar Yue Gan <yueg@google.com>2017-02-15 19:19:54 +0000
commitb535e6df1eda2a799647c9db9a0b9e1baa26f0bc (patch)
tree0c8ed9825c753326015fcc1037ec44fca1949547 /src/main/cpp/util/errors.cc
parent9d88394848fa6742513d85fa5f892ae1702d015e (diff)
Bazel client: refactors, small bugfixes
In this change: * Fix pdie and PrintError to acquire the last error string as the first thing the method does, otherwise we may display an error coming from pdie's/PrintError's own logic * Auto-close file handles in file_test in order to avoid leaking them in case an assertion fails (which means an early return from the function) -- Change-Id: Ia4392b42cbc93b931dcee76993db0ad264d0c147 Reviewed-on: https://cr.bazel.build/8932 PiperOrigin-RevId: 147610527 MOS_MIGRATED_REVID=147610527
Diffstat (limited to 'src/main/cpp/util/errors.cc')
-rw-r--r--src/main/cpp/util/errors.cc6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/main/cpp/util/errors.cc b/src/main/cpp/util/errors.cc
index 112f293bf1..ba23b7ea87 100644
--- a/src/main/cpp/util/errors.cc
+++ b/src/main/cpp/util/errors.cc
@@ -31,22 +31,24 @@ void die(const int exit_status, const char *format, ...) {
}
void pdie(const int exit_status, const char *format, ...) {
+ const char *errormsg = GetLastErrorString().c_str();
fprintf(stderr, "Error: ");
va_list ap;
va_start(ap, format);
vfprintf(stderr, format, ap);
va_end(ap);
- fprintf(stderr, ": %s\n", GetLastErrorString().c_str());
+ fprintf(stderr, ": %s\n", errormsg);
exit(exit_status);
}
void PrintError(const char *format, ...) {
+ const char *errormsg = GetLastErrorString().c_str();
fprintf(stderr, "Error: ");
va_list ap;
va_start(ap, format);
vfprintf(stderr, format, ap);
va_end(ap);
- fprintf(stderr, ": %s\n", GetLastErrorString().c_str());
+ fprintf(stderr, ": %s\n", errormsg);
}
} // namespace blaze_util