Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
eval-error.hh
1#pragma once
2
3#include "nix/util/error.hh"
4#include "nix/util/pos-idx.hh"
5#include "nix/store/path.hh"
6
7namespace nix {
8
9struct Env;
10struct Expr;
11struct Value;
12
13class EvalState;
14template<class T>
16
22class EvalBaseError : public CloneableError<EvalBaseError, Error>
23{
24 template<class T>
25 friend class EvalErrorBuilder;
26
27 void anchor() override;
28
29public:
30 EvalState & state;
31
32 EvalBaseError(EvalState & state, ErrorInfo && errorInfo)
33 : CloneableError(errorInfo)
34 , state(state)
35 {
36 }
37
38 template<typename... Args>
39 explicit EvalBaseError(EvalState & state, const std::string & formatString, const Args &... formatArgs)
40 : CloneableError(formatString, formatArgs...)
41 , state(state)
42 {
43 }
44};
45
52MakeError(EvalError, EvalBaseError);
53MakeError(AssertionError, EvalError);
54MakeError(ThrownError, AssertionError);
55MakeError(Abort, EvalError);
56MakeError(TypeError, EvalError);
57MakeError(UndefinedVarError, EvalError);
58MakeError(MissingArgumentError, EvalError);
59
60class ParseError final : public CloneableError<ParseError, Error>
61{
62 bool isUnexpectedEOF = false;
63
64 void anchor() override;
65
66public:
67 using CloneableError::CloneableError;
68
69 ParseError && setIncomplete(bool val) &&
70 {
71 isUnexpectedEOF = val;
72 return std::move(*this);
73 }
74
78 bool isIncomplete() const noexcept
79 {
80 return isUnexpectedEOF;
81 }
82};
83
84class InfiniteRecursionError : public CloneableError<InfiniteRecursionError, EvalError>
85{
86 void anchor() override;
87
88public:
89
95 const Value * const v;
96
97 template<typename... Args>
98 explicit InfiniteRecursionError(EvalState & state, const Value * v, const Args &... args)
99 : CloneableError(state, args...)
100 , v(v)
101 {
102 }
103};
104
110class StackOverflowError : public CloneableError<StackOverflowError, EvalBaseError>
111{
112 void anchor() override;
113
114public:
115 StackOverflowError(EvalState & state)
116 : CloneableError(state, "stack overflow; max-call-depth exceeded")
117 {
118 }
119};
120
121MakeError(IFDError, EvalBaseError);
122
129MakeError(RecoverableEvalError, EvalBaseError);
130
131class InvalidPathError : public CloneableError<InvalidPathError, EvalError>
132{
133 void anchor() override;
134
135public:
136 StorePath path;
137
138 InvalidPathError(EvalState & state, const StorePath & path);
139};
140
146template<class T>
147class EvalErrorBuilder final
148{
149 friend class EvalState;
150
151 template<typename... Args>
152 explicit EvalErrorBuilder(EvalState & state, const Args &... args)
153 : error(T(state, args...))
154 {
155 }
156
157public:
158 T error;
159
160 [[nodiscard, gnu::noinline]] EvalErrorBuilder<T> & withExitStatus(unsigned int exitStatus);
161
162 [[nodiscard, gnu::noinline]] EvalErrorBuilder<T> & atPos(PosIdx pos);
163
164 [[nodiscard, gnu::noinline]] EvalErrorBuilder<T> & atPos(Value & value, PosIdx fallback = noPos);
165
166 [[nodiscard, gnu::noinline]] EvalErrorBuilder<T> & withTrace(PosIdx pos, const std::string_view text);
167
168 [[nodiscard, gnu::noinline]] EvalErrorBuilder<T> & withFrameTrace(PosIdx pos, const std::string_view text);
169
170 [[nodiscard, gnu::noinline]] EvalErrorBuilder<T> & withSuggestions(Suggestions & s);
171
172 [[nodiscard, gnu::noinline]] EvalErrorBuilder<T> & withFrame(const Env & e, const Expr & ex);
173
174 [[nodiscard, gnu::noinline]] EvalErrorBuilder<T> & addTrace(PosIdx pos, HintFmt hint);
175
176 [[nodiscard, gnu::noinline]] EvalErrorBuilder<T> & setIsFromExpr();
177
178 template<typename... Args>
179 [[nodiscard, gnu::noinline]] EvalErrorBuilder<T> &
180 addTrace(PosIdx pos, std::string_view formatString, const Args &... formatArgs);
181
185 [[gnu::noinline, gnu::noreturn]] void debugThrow();
186
191 [[gnu::noinline, gnu::noreturn]] void panic();
192};
193
194} // namespace nix
Definition args.hh:29
Definition eval-error.hh:23
Definition eval-error.hh:148
void debugThrow()
Definition eval-error.cc:89
void panic()
Definition eval-error.cc:104
Definition eval.hh:420
Definition fmt.hh:169
const Value *const v
Definition eval-error.hh:95
Definition eval-error.hh:61
bool isIncomplete() const noexcept
Definition eval-error.hh:78
Definition pos-idx.hh:10
Definition path.hh:33
Definition suggestions.hh:28
This file defines two main structs/classes used in nix error handling.
Definition eval.hh:197
Definition error.hh:109
Definition nixexpr.hh:100
Definition value.hh:1166