![]() |
Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
|
This file defines two main structs/classes used in nix error handling. More...
#include "nix/util/suggestions.hh"#include "nix/util/fmt.hh"#include "nix/util/fun.hh"#include "nix/util/config.hh"#include <concepts>#include <exception>#include <list>#include <memory>#include <optional>#include <utility>#include <algorithm>#include <type_traits>Go to the source code of this file.
Classes | |
| struct | nix::LinesOfCode |
| struct | nix::Trace |
| struct | nix::ErrorInfo |
| class | nix::BaseError |
| class | nix::CloneableError< Derived, Base > |
| class | nix::Error |
| class | nix::UsageError |
| class | nix::UnimplementedError |
Macros | |
| #define | MakeError(newClass, superClass) |
| #define | nixUnreachableWhenHardened std::unreachable |
Enumerations | |
| enum class | Verbosity : unsigned { lvlError = 0 , lvlWarn , lvlNotice , lvlInfo , lvlTalkative , lvlChatty , lvlDebug , lvlVomit } |
| enum struct | nix::TracePrint { Default , Always } |
| enum class | Verbosity |
Functions | |
|
template<std::integral T> requires (std::is_unsigned_v<T> && !std::is_same_v<bool, T>) | |
| Verbosity | nix::verbosityFromIntClamped (T val) |
|
template<std::integral T> requires std::is_signed_v<T> | |
| Verbosity | nix::verbosityFromIntClamped (T)=delete |
| void | nix::printCodeLines (std::ostream &out, const std::string &prefix, const Pos &errPos, const LinesOfCode &loc) |
| std::strong_ordering | nix::operator<=> (const Trace &lhs, const Trace &rhs) |
| std::ostream & | nix::showErrorInfo (std::ostream &out, const ErrorInfo &einfo, bool showTrace) |
| void | nix::rethrowExceptionCopy (std::exception_ptr ex) |
| void | nix::throwExceptionSelfCheck () |
| void | nix::panic (std::string_view msg) |
| int | nix::handleExceptions (const std::string &programName, fun< void()> body) |
| void | nix::unreachable (std::source_location loc) |
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.
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. See libutil/tests/logging.cc for usage examples.
| #define MakeError | ( | newClass, | |
| superClass ) |
|
strong |
| int nix::handleExceptions | ( | const std::string & | programName, |
| fun< void()> | body ) |
Run a function, printing an error and returning on exception. Useful for wrapping a main function that may throw
| programName | Name of program, usually argv[0] |
| body | Function to run inside the try block |
An arbitrarily defined value comparison for the purpose of using traces in the key of a sorted container.
| void nix::panic | ( | std::string_view | msg | ) |
Print a message and std::terminate().
| void nix::rethrowExceptionCopy | ( | std::exception_ptr | ex | ) |
Like std::rethrow_exception, but if ex is a BaseError, throw a copy of it rather than the original, so that handlers which modify what they catch (e.g. by adding traces) leave the stored exception alone.
| void nix::throwExceptionSelfCheck | ( | ) |
Throw an exception for the purpose of checking that exception handling works; see 'initLibUtil()'.
| void nix::unreachable | ( | std::source_location | loc = std::source_location::current() | ) |
Print a basic error message with source position and std::terminate().