Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
nix::BaseError Class Referenceabstract

#include <error.hh>

Inheritance diagram for nix::BaseError:
nix::CloneableError< Error, BaseError > nix::Error nix::CloneableError< BadNixStringContextElem, Error > nix::CloneableError< BuildEnvFileConflictError, Error > nix::CloneableError< BuildError, Error > nix::CloneableError< EvalBaseError, Error > nix::CloneableError< ExecError, Error > nix::CloneableError< FileTransferError, Error > nix::CloneableError< InvalidSSHAuthority, Error > nix::CloneableError< MissingExperimentalFeature, Error > nix::CloneableError< MissingRealisation, Error > nix::CloneableError< ParseError, Error > nix::CloneableError< SQLiteError, Error > nix::CloneableError< SymlinkNotAllowed, Error > nix::CloneableError< SystemError, Error > nix::CloneableError< UnimplementedError, Error > nix::CloneableError< UsageError, Error >

Public Member Functions

 BaseError (const BaseError &)=default
BaseError & operator= (const BaseError &)=default
BaseError & operator= (BaseError &&) noexcept=default
template<typename... Args>
 BaseError (unsigned int status, Args &&... args)
template<typename... Args>
 BaseError (const std::string &fs, Args &&... args)
template<typename... Args>
 BaseError (const Suggestions &sug, Args &&... args)
 BaseError (HintFmt hint)
 BaseError (ErrorInfo &&e)
 BaseError (const ErrorInfo &e)
std::string message () const
const char * what () const noexcept override
const std::string & msg () const
const ErrorInfo & info () const
void withExitStatus (unsigned int status)
void atPos (std::shared_ptr< const Pos > pos)
bool hasPos () const
void pushTrace (Trace trace)
template<typename... Args>
void addTrace (std::shared_ptr< const Pos > &&pos, std::string_view fs, Args &&... args)
void addTrace (std::shared_ptr< const Pos > &&pos, HintFmt hint, TracePrint print=TracePrint::Default)
bool hasTrace () const
ErrorInfo & unsafeInfo ()
void recalcWhat () const
virtual void throwClone () const =0

Protected Member Functions

const std::string & calcWhat () const

Protected Attributes

ErrorInfo err
std::optional< std::string > what_

Detailed Description

BaseError should generally not be caught, as it has Interrupted as a subclass. Catch Error instead.

Member Function Documentation

◆ addTrace() [1/2]

void nix::BaseError::addTrace ( std::shared_ptr< const Pos > && pos,
HintFmt hint,
TracePrint print = TracePrint::Default )

Prepends an item to the error trace, as is usual for extra context.

Parameters
posNullable source position to put in trace item
hintFormatted error message
printOptional, whether to always print (used by addErrorContext)

◆ addTrace() [2/2]

template<typename... Args>
void nix::BaseError::addTrace ( std::shared_ptr< const Pos > && pos,
std::string_view fs,
Args &&... args )
inline

Prepends an item to the error trace, as is usual for extra context.

Parameters
posNullable source position to put in trace item
fsFormat string, see HintFmt
argsFormat string arguments.

◆ calcWhat()

const std::string & nix::BaseError::calcWhat ( ) const
protected

Format err.msg and set what_ to the resulting value.

◆ message()

std::string nix::BaseError::message ( ) const
inline

The error message without "error: " prefixed to it.

◆ recalcWhat()

void nix::BaseError::recalcWhat ( ) const

Recalculate the cached formatted error message. Must be called after modifying the error info via unsafeInfo().

◆ throwClone()

◆ unsafeInfo()

ErrorInfo & nix::BaseError::unsafeInfo ( )
inline

Returns a mutable reference to the error info.

Warning
After modifying the returned ErrorInfo, you must call recalcWhat() to update the cached formatted message.

Member Data Documentation

◆ what_

std::optional<std::string> nix::BaseError::what_
mutableprotected

Cached formatted contents of err.msg.


The documentation for this class was generated from the following files:
  • libutil/include/nix/util/error.hh
  • libutil/error.cc