13#include <nix/nixexpr.hh>
14#include <nlohmann/json.hpp>
147 if (
contextMsg.has_value() ) { this->whatMsg +=
": " + ( *contextMsg ); }
148 if (
caughtMsg.has_value() ) { this->whatMsg +=
": " + ( *caughtMsg ); }
153 getErrorCode() const noexcept
158 [[nodiscard]] std::optional<std::string>
159 getContextMessage() const noexcept
164 [[nodiscard]] std::optional<std::string>
165 getCaughtMessage() const noexcept
170 [[nodiscard]]
virtual std::string_view
171 getCategoryMessage() const noexcept
173 return "general error";
177 [[nodiscard]]
const char *
180 return this->whatMsg.c_str();
191to_json( nlohmann::json & jto,
const FloxException & err );
206#define FLOX_DEFINE_EXCEPTION( NAME, ERROR_CODE, CATEGORY_MSG ) \
207 class NAME : public FloxException \
211 NAME() : FloxException( CATEGORY_MSG, std::nullopt, std::nullopt ) {} \
213 explicit NAME( std::string_view contextMsg ) \
214 : FloxException( ( CATEGORY_MSG ), \
215 std::string( contextMsg ), \
219 explicit NAME( std::string_view contextMsg, std::string_view caughtMsg ) \
220 : FloxException( ( CATEGORY_MSG ), \
221 std::string( contextMsg ), \
222 std::string( caughtMsg ) ) \
225 [[nodiscard]] error_category \
226 getErrorCode() const noexcept override \
228 return ( ERROR_CODE ); \
231 [[nodiscard]] std::string_view \
232 getCategoryMessage() const noexcept override \
234 return ( CATEGORY_MSG ); \
249 const nix::EvalError & err )
252 nix::filterANSIEscapes( err.what(),
true ) )
256 getErrorCode()
const noexcept override
261 [[nodiscard]] std::string_view
262 getCategoryMessage()
const noexcept override
264 return "Nix evaluation error";
Definition: exceptions.hh:88
FloxException(std::string_view contextMsg)
Create a generic exception with a custom message.
Definition: exceptions.hh:112
std::optional< std::string > caughtMsg
Definition: exceptions.hh:99
const char * what() const noexcept override
Produces an explanatory string about an exception.
Definition: exceptions.hh:178
std::string whatMsg
Definition: exceptions.hh:102
FloxException(std::string_view contextMsg, std::string_view caughtMsg)
Create a generic exception with a custom message and information from a child error.
Definition: exceptions.hh:123
FloxException(std::string_view categoryMsg, std::optional< std::string > contextMsg, std::optional< std::string > caughtMsg)
Directly initialize a FloxException with a custom category message, (optional) context,...
Definition: exceptions.hh:140
std::optional< std::string > contextMsg
Definition: exceptions.hh:93
An exception thrown when a hash string is invalid.
A nix::EvalError was encountered.
Definition: exceptions.hh:244
#define FLOX_DEFINE_EXCEPTION(NAME, ERROR_CODE, CATEGORY_MSG)
Generate a class definition with an error code and category message.
Definition: exceptions.hh:206
Interfaces for use by flox.
Definition: command.cc:29
error_category
Definition: exceptions.hh:26
@ EC_JSON
Definition: exceptions.hh:67
@ EC_INVALID_HASH
Definition: exceptions.hh:75
@ EC_INVALID_PKG_QUERY_ARG
Definition: exceptions.hh:41
@ EC_ENVIRONMENT_MIXIN
Definition: exceptions.hh:79
@ EC_PARSE_RESOLVED
Definition: exceptions.hh:59
@ EC_PARSE_SEARCH_QUERY
Definition: exceptions.hh:61
@ EC_NIX
Definition: exceptions.hh:49
@ EC_PARSE_MANIFEST_DESCRIPTOR_RAW
Definition: exceptions.hh:57
@ EC_INVALID_ARG
Definition: exceptions.hh:37
@ EC_INVALID_LOCKFILE
Definition: exceptions.hh:73
@ EC_INVALID_MANIFEST_FILE
Definition: exceptions.hh:45
@ EC_INVALID_MANIFEST_DESCRIPTOR
Definition: exceptions.hh:39
@ EC_SQLITE3
Definition: exceptions.hh:65
@ EC_FLOX_EXCEPTION
Definition: exceptions.hh:35
@ EC_YAML_TO_JSON
Definition: exceptions.hh:71
@ EC_FAILURE
Definition: exceptions.hh:33
@ EC_TOML_TO_JSON
Definition: exceptions.hh:69
@ EC_RESOLUTION_FAILURE
Definition: exceptions.hh:77
@ EC_PACKAGE_INIT
Definition: exceptions.hh:55
@ EC_OKAY
Definition: exceptions.hh:28
@ EC_NIX_EVAL
Definition: exceptions.hh:51
@ EC_NIX_LOCK_FLAKE
Definition: exceptions.hh:53
@ EC_PKG_DB
Definition: exceptions.hh:63
@ EC_INVALID_REGISTRY
Definition: exceptions.hh:43
void to_json(nlohmann::json &jto, const FloxException &err)
Convert a flox::FloxException to a JSON object.
Definition: exceptions.cc:27