Nix  2.93.0-dev
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
10namespace nix {
11
12struct DebugState;
13struct DebugTrace;
14struct Env;
15struct Expr;
16struct Value;
17
18class EvalState;
19template<class T>
20class EvalErrorBuilder;
21
22class EvalError : public Error
23{
24 template<class T>
25 friend class EvalErrorBuilder;
26
27 std::shared_ptr<const DebugTrace> frame;
28
29public:
30 using Error::Error;
31};
32
33MakeError(ParseError, Error);
34MakeError(AssertionError, EvalError);
35MakeError(ThrownError, AssertionError);
36MakeError(Abort, EvalError);
37MakeError(TypeError, EvalError);
38MakeError(UndefinedVarError, EvalError);
39MakeError(MissingArgumentError, EvalError);
40MakeError(RestrictedPathError, Error);
41MakeError(InfiniteRecursionError, EvalError);
42
48{
49public:
50 Path path;
51 InvalidPathError(const Path & path)
52 : EvalError("path '%s' did not exist in the store during evaluation", path)
53 {
54 }
55};
56
57template<class T>
58class [[nodiscard]] EvalErrorBuilder final
59{
60 const PosTable & positions;
61 DebugState * debug;
62 box_ptr<T> error;
63
64public:
65 template<typename... Args>
66 explicit EvalErrorBuilder(const PosTable & positions, DebugState * debug, const Args &... args)
67 : positions(positions)
68 , debug{debug}
69 , error(make_box_ptr<T>(args...))
70 {
71 }
72
73 [[gnu::noinline]] EvalErrorBuilder<T> withExitStatus(unsigned int exitStatus) &&;
74
75 [[gnu::noinline]] EvalErrorBuilder<T> atPos(PosIdx pos) &&;
76
77 [[gnu::noinline]] EvalErrorBuilder<T> atPos(Value & value, PosIdx fallback = noPos) &&;
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:59
Definition eval-error.hh:23
Definition fmt.hh:157
Definition pos-idx.hh:9
Definition pos-table.hh:16
Definition suggestions.hh:29
Definition box_ptr.hh:16
This file defines two main structs/classes used in nix error handling.
Definition eval.hh:153
Definition eval.hh:118
Definition nixexpr.hh:47
Definition eval-error.hh:48
Definition types.hh:166
Definition value.hh:191
std::string Path
Definition types.hh:28