Nix 2.93.3
Lix: A modern, delicious implementation of the Nix package manager; unstable internal interfaces
Loading...
Searching...
No Matches
error.hh File Reference

This file defines two main structs/classes used in nix error handling. More...

#include "lix/libutil/json-fwd.hh"
#include "lix/libutil/suggestions.hh"
#include "lix/libutil/fmt.hh"
#include <cstring>
#include <exception>
#include <list>
#include <memory>
#include <optional>
#include <source_location>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <system_error>
#include <type_traits>

Go to the source code of this file.

Classes

struct  nix::json::is_integral_enum< Verbosity >
struct  nix::LinesOfCode
struct  nix::Trace
struct  nix::ErrorInfo
class  nix::BaseException
struct  nix::BaseException::AsyncTraceFrame
class  nix::BaseError
class  nix::ForeignException
class  nix::SysError

Macros

#define MakeError(newClass, superClass)

Enumerations

enum  Verbosity {
  lvlError = 0 , lvlWarn , lvlNotice , lvlInfo ,
  lvlTalkative , lvlChatty , lvlDebug , lvlVomit
}

Functions

Verbosity nix::verbosityFromIntClamped (int val)
void nix::printCodeLines (std::ostream &out, const std::string &prefix, const Pos &errPos, const LinesOfCode &loc)
bool nix::operator< (const Trace &lhs, const Trace &rhs)
bool nix::operator> (const Trace &lhs, const Trace &rhs)
bool nix::operator<= (const Trace &lhs, const Trace &rhs)
bool nix::operator>= (const Trace &lhs, const Trace &rhs)
std::ostream & nix::showErrorInfo (std::ostream &out, const ErrorInfo &einfo, bool showTrace)
 nix::MakeError (Error, BaseError)
 nix::MakeError (UsageError, Error)
 nix::MakeError (UnimplementedError, Error)
void nix::ignoreExceptionInDestructor (Verbosity lvl)
void nix::ignoreExceptionExceptInterrupt (Verbosity lvl)

Detailed Description

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.

Macro Definition Documentation

◆ MakeError

#define MakeError ( newClass,
superClass )
Value:
/* NOLINTNEXTLINE(bugprone-macro-parentheses) */ \
class newClass : public superClass \
{ \
public: \
using superClass::superClass; \
}

Function Documentation

◆ ignoreExceptionExceptInterrupt()

void nix::ignoreExceptionExceptInterrupt ( Verbosity lvl = lvlError)

Not destructor-safe. Print an error message, then ignore the exception. If the exception is an Interrupted exception, rethrow it.

This may be used in a few places where Interrupt can't happen, but that's ok.

◆ ignoreExceptionInDestructor()

void nix::ignoreExceptionInDestructor ( Verbosity lvl = lvlError)

Exception handling in destructors: print an error message, then ignore the exception.

If you're not in a destructor, you usually want to use ignoreExceptionExceptInterrupt().

This function might also be used in callbacks whose caller may not handle exceptions, but ideally we propagate the exception using an exception_ptr in such cases. See e.g. PackBuilderContext

◆ operator<()

bool nix::operator< ( const Trace & lhs,
const Trace & rhs )
inline

An arbitrarily defined value comparison for the purpose of using traces in the key of a sorted container.