mirror of
https://github.com/NixOS/nix
synced 2025-06-28 01:11:15 +02:00
addTrace
This commit is contained in:
parent
e6f93b94fc
commit
4d1a4f0217
3 changed files with 59 additions and 44 deletions
|
@ -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...);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue