Nix 2.93.3
Lix: A modern, delicious implementation of the Nix package manager; unstable internal interfaces
Loading...
Searching...
No Matches
eval-error.hh
Go to the documentation of this file.
1#pragma once
3
9#include <concepts>
10
11namespace nix {
12
13struct DebugState;
14struct DebugTrace;
15struct Env;
16struct Expr;
17struct Value;
18
19class EvalError;
20class EvalState;
21template<std::derived_from<EvalError> T>
23
24class EvalError : public Error
25{
26 template<std::derived_from<EvalError> T>
27 friend class EvalErrorBuilder;
28
29 std::shared_ptr<const DebugTrace> frame;
30
31public:
32 using Error::Error;
33};
34
35MakeError(ParseError, Error);
36MakeError(AssertionError, EvalError);
37MakeError(ThrownError, AssertionError);
38MakeError(Abort, EvalError);
39MakeError(TypeError, EvalError);
40MakeError(UndefinedVarError, EvalError);
41MakeError(MissingArgumentError, EvalError);
42MakeError(RestrictedPathError, Error);
43MakeError(InfiniteRecursionError, EvalError);
44
49struct InvalidPathError : public EvalError
50{
51public:
52 Path path;
53 InvalidPathError(const Path & path)
54 : EvalError("path '%s' did not exist in the store during evaluation", path)
55 {
56 }
57};
58
59template<std::derived_from<EvalError> T>
60class [[nodiscard]] EvalErrorBuilder final
61{
62 const PosTable & positions;
63 DebugState * debug;
64 box_ptr<T> error;
65
66public:
67 template<typename... Args>
68 explicit EvalErrorBuilder(const PosTable & positions, DebugState * debug, const Args &... args)
69 : positions(positions)
70 , debug{debug}
71 , error(make_box_ptr<T>(args...))
72 {
73 }
74
75 [[gnu::noinline]] EvalErrorBuilder<T> withExitStatus(unsigned int exitStatus) &&;
76
77 [[gnu::noinline]] EvalErrorBuilder<T> atPos(PosIdx pos) &&;
78
79 [[gnu::noinline]] EvalErrorBuilder<T> withTrace(PosIdx pos, const std::string_view text) &&;
80
81 [[gnu::noinline]] EvalErrorBuilder<T> withSuggestions(Suggestions & s) &&;
82
83 [[gnu::noinline]] EvalErrorBuilder<T> withFrame(const Env & e, const Expr & ex) &&;
84
85 [[gnu::noinline]] EvalErrorBuilder<T> addTrace(PosIdx pos, HintFmt hint) &&;
86
87 template<typename... Args>
88 [[gnu::noinline]] EvalErrorBuilder<T>
89 addTrace(PosIdx pos, std::string_view formatString, const Args &... formatArgs) &&;
90
94 [[gnu::noinline, gnu::noreturn]] void debugThrow(NeverAsync = {}) &&;
95
99 [[gnu::noinline, gnu::noreturn]] void throw_() &&;
100};
101
102}
Definition args.hh:31
Definition eval-error.hh:61
void debugThrow(NeverAsync={}) &&
Definition eval-error.cc:70
void throw_() &&
Definition eval-error.cc:84
Definition eval-error.hh:25
Definition eval.hh:685
Definition fmt.hh:157
Definition pos-idx.hh:9
Definition pos-table.hh:13
Definition suggestions.hh:29
Definition box_ptr.hh:16
This file defines two main structs/classes used in nix error handling.
Definition eval.hh:147
Definition eval.hh:137
Definition eval.hh:112
Definition nixexpr.hh:104
Definition types.hh:172
Definition value.hh:190
std::string Path
Definition types.hh:28