Nix 2.26.3
Nix, the purely functional 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 "suggestions.hh"
#include "fmt.hh"
#include <cstring>
#include <list>
#include <memory>
#include <optional>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

Go to the source code of this file.

Classes

struct  nix::LinesOfCode
 
struct  nix::Trace
 
struct  nix::ErrorInfo
 
class  nix::BaseError
 
class  nix::SysError
 

Macros

#define MakeError(newClass, superClass)
 
#define unreachable()
 

Typedefs

using nix::NativeSysError
 

Enumerations

enum  Verbosity {
  lvlError = 0 , lvlWarn , lvlNotice , lvlInfo ,
  lvlTalkative , lvlChatty , lvlDebug , lvlVomit
}
 
enum struct  nix::TracePrint { Default , Always }
 

Functions

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)
 
 nix::MakeError (Error, BaseError)
 
 nix::MakeError (UsageError, Error)
 
 nix::MakeError (UnimplementedError, Error)
 
 nix::MakeError (SystemError, Error)
 
void nix::throwExceptionSelfCheck ()
 
void nix::panic (std::string_view msg)
 
void nix::panic (const char *file, int line, const char *func)
 

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:
class newClass : public superClass \
{ \
public: \
using superClass::superClass; \
}

◆ unreachable

#define unreachable ( )
Value:
(::nix::panic(__FILE__, __LINE__, __func__))

Print a basic error message with source position and abort().

Note
: This assumes that the logger is operational

Typedef Documentation

◆ NativeSysError

Initial value:
Definition error.hh:222

Convenience alias for when we use a errno-based error handling function on Unix, and GetLastError()-based error handling on on Windows.

Enumeration Type Documentation

◆ TracePrint

enum struct nix::TracePrint
strong

When a stack frame is printed.

Enumerator
Default 

The default behavior; always printed when --show-trace is set.

Always 

Always printed. Produced by builtins.addErrorContext.

Function Documentation

◆ MakeError()

nix::MakeError ( SystemError ,
Error  )

To use in catch-blocks.

◆ operator<=>()

std::strong_ordering 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.

◆ panic() [1/2]

void nix::panic ( const char * file,
int line,
const char * func )

Print a basic error message with source position and abort(). Use the unreachable() macro to call this.

◆ panic() [2/2]

void nix::panic ( std::string_view msg)

Print a message and abort().

◆ throwExceptionSelfCheck()

void nix::throwExceptionSelfCheck ( )

Throw an exception for the purpose of checking that exception handling works; see 'initLibUtil()'.