aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/error.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/libutil/error.hh')
-rw-r--r--src/libutil/error.hh47
1 files changed, 27 insertions, 20 deletions
diff --git a/src/libutil/error.hh b/src/libutil/error.hh
index 8494b9412..10bdeea1d 100644
--- a/src/libutil/error.hh
+++ b/src/libutil/error.hh
@@ -25,20 +25,20 @@ namespace nix {
/*
-This file defines two main structs/classes used in nix error handling.
+ This file defines two main structs/classes used in nix error handling.
-ErrorInfo provides a standard payload of error information, with conversion to string
-happening in the logger rather than at the call site.
+ ErrorInfo provides a standard payload of error information, with conversion to string
+ happening in the logger rather than at the call site.
-BaseError is the ancestor of nix specific exceptions (and Interrupted), and contains
-an ErrorInfo.
+ BaseError is the ancestor of nix specific exceptions (and Interrupted), and contains
+ an ErrorInfo.
-ErrorInfo structs are sent to the logger as part of an exception, or directly with the
-logError or logWarning macros.
+ ErrorInfo structs are sent to the logger as part of an exception, or directly with the
+ logError or logWarning macros.
-See the error-demo.cc program for usage examples.
+ See the error-demo.cc program for usage examples.
-*/
+ */
typedef enum {
lvlError = 0,
@@ -50,7 +50,7 @@ typedef enum {
lvlVomit
} Verbosity;
-typedef enum {
+typedef enum {
foFile,
foStdin,
foString
@@ -93,12 +93,18 @@ struct NixCode {
std::optional<string> nextLineOfCode;
};
+struct Trace {
+ ErrPos pos;
+ hintformat hint;
+};
+
struct ErrorInfo {
Verbosity level;
string name;
string description;
std::optional<hintformat> hint;
std::optional<NixCode> nixCode;
+ std::list<Trace> traces;
static std::optional<string> programName;
};
@@ -121,23 +127,23 @@ public:
template<typename... Args>
BaseError(unsigned int status, const Args & ... args)
- : err { .level = lvlError,
- .hint = hintfmt(args...)
- }
+ : err {.level = lvlError,
+ .hint = hintfmt(args...)
+ }
, status(status)
{ }
template<typename... Args>
BaseError(const std::string & fs, const Args & ... args)
- : err { .level = lvlError,
- .hint = hintfmt(fs, args...)
- }
+ : err {.level = lvlError,
+ .hint = hintfmt(fs, args...)
+ }
{ }
BaseError(hintformat hint)
- : err { .level = lvlError,
- .hint = hint
- }
+ : err {.level = lvlError,
+ .hint = hint
+ }
{ }
BaseError(ErrorInfo && e)
@@ -160,6 +166,7 @@ public:
const string & msg() const { return calcWhat(); }
const string & prefix() const { return prefix_; }
BaseError & addPrefix(const FormatOrString & fs);
+ BaseError & addTrace(ErrPos e, hintformat hint);
const ErrorInfo & info() { calcWhat(); return err; }
};
@@ -181,7 +188,7 @@ public:
template<typename... Args>
SysError(const Args & ... args)
- :Error("")
+ : Error("")
{
errNo = errno;
auto hf = hintfmt(args...);