From 39ff80d031c5c9c1831ba5ea597c0de0181bfe34 Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Wed, 29 Apr 2020 18:57:05 -0600 Subject: [PATCH] errorinfo constructor test --- src/error-demo/error-demo.cc | 10 ++++++++++ src/libstore/binary-cache-store.cc | 2 +- src/libstore/remote-store.cc | 2 +- src/libutil/error.hh | 7 ++++--- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/error-demo/error-demo.cc b/src/error-demo/error-demo.cc index 437a761c4..2c4f2da6e 100644 --- a/src/error-demo/error-demo.cc +++ b/src/error-demo/error-demo.cc @@ -23,6 +23,16 @@ int main() logger->logEI(e.info()); } + + // ErrorInfo constructor + try { + auto e = Error("generic error"); + throw DemoError(e.info()); + } catch (Error &e) { + logger->logEI(e.info()); + } + + // For completeness sake, info through vomit levels. // But this is maybe a heavy format for those. logger->logEI( diff --git a/src/libstore/binary-cache-store.cc b/src/libstore/binary-cache-store.cc index 4b7385c6b..97e34a75d 100644 --- a/src/libstore/binary-cache-store.cc +++ b/src/libstore/binary-cache-store.cc @@ -284,7 +284,7 @@ void BinaryCacheStore::narFromPath(const StorePath & storePath, Sink & sink) try { getFile(info->url, *decompressor); } catch (NoSuchBinaryCacheFile & e) { - throw SubstituteGone(e.what()); + throw SubstituteGone(e.info()); } decompressor->finish(); diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index 0f8126aee..cc336e460 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -365,7 +365,7 @@ void RemoteStore::queryPathInfoUncached(const StorePath & path, } catch (Error & e) { // Ugly backwards compatibility hack. if (e.msg().find("is not valid") != std::string::npos) - throw InvalidPath(e.what()); + throw InvalidPath(e.info()); throw; } if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 17) { diff --git a/src/libutil/error.hh b/src/libutil/error.hh index 03e43241f..48e6311bd 100644 --- a/src/libutil/error.hh +++ b/src/libutil/error.hh @@ -83,6 +83,7 @@ class BaseError : public std::exception protected: string prefix_; // used for location traces etc. ErrorInfo err; + std::optional what_; const string& calcWhat() { @@ -107,18 +108,18 @@ public: .hint = hintfmt(args...) } , status(status) - { } + { } template BaseError(const Args & ... args) : err { .level = lvlError, .hint = hintfmt(args...) } - { } + { } BaseError(ErrorInfo e) : err(e) - { } + { } virtual const char* sname() const { return "BaseError"; }