Nix 2.26.3
Nix, the purely functional package manager; unstable internal interfaces
 
Loading...
Searching...
No Matches
eval-error.hh
1#pragma once
2
3#include "error.hh"
4#include "pos-idx.hh"
5
6namespace nix {
7
8struct Env;
9struct Expr;
10struct Value;
11
12class EvalState;
13template<class T>
15
21class EvalBaseError : public Error
22{
23 template<class T>
24 friend class EvalErrorBuilder;
25public:
26 EvalState & state;
27
28 EvalBaseError(EvalState & state, ErrorInfo && errorInfo)
29 : Error(errorInfo)
30 , state(state)
31 {
32 }
33
34 template<typename... Args>
35 explicit EvalBaseError(EvalState & state, const std::string & formatString, const Args &... formatArgs)
36 : Error(formatString, formatArgs...)
37 , state(state)
38 {
39 }
40};
41
48MakeError(EvalError, EvalBaseError);
49MakeError(ParseError, Error);
50MakeError(AssertionError, EvalError);
51MakeError(ThrownError, AssertionError);
52MakeError(Abort, EvalError);
53MakeError(TypeError, EvalError);
54MakeError(UndefinedVarError, EvalError);
55MakeError(MissingArgumentError, EvalError);
56MakeError(InfiniteRecursionError, EvalError);
57
58struct InvalidPathError : public EvalError
59{
60public:
61 Path path;
62 InvalidPathError(EvalState & state, const Path & path)
63 : EvalError(state, "path '%s' is not valid", path)
64 {
65 }
66};
67
73template<class T>
74class EvalErrorBuilder final
75{
76 friend class EvalState;
77
78 template<typename... Args>
79 explicit EvalErrorBuilder(EvalState & state, const Args &... args)
80 : error(T(state, args...))
81 {
82 }
83
84public:
85 T error;
86
87 [[nodiscard, gnu::noinline]] EvalErrorBuilder<T> & withExitStatus(unsigned int exitStatus);
88
89 [[nodiscard, gnu::noinline]] EvalErrorBuilder<T> & atPos(PosIdx pos);
90
91 [[nodiscard, gnu::noinline]] EvalErrorBuilder<T> & atPos(Value & value, PosIdx fallback = noPos);
92
93 [[nodiscard, gnu::noinline]] EvalErrorBuilder<T> & withTrace(PosIdx pos, const std::string_view text);
94
95 [[nodiscard, gnu::noinline]] EvalErrorBuilder<T> & withFrameTrace(PosIdx pos, const std::string_view text);
96
97 [[nodiscard, gnu::noinline]] EvalErrorBuilder<T> & withSuggestions(Suggestions & s);
98
99 [[nodiscard, gnu::noinline]] EvalErrorBuilder<T> & withFrame(const Env & e, const Expr & ex);
100
101 [[nodiscard, gnu::noinline]] EvalErrorBuilder<T> & addTrace(PosIdx pos, HintFmt hint);
102
103 [[nodiscard, gnu::noinline]] EvalErrorBuilder<T> & setIsFromExpr();
104
105 template<typename... Args>
106 [[nodiscard, gnu::noinline]] EvalErrorBuilder<T> &
107 addTrace(PosIdx pos, std::string_view formatString, const Args &... formatArgs);
108
112 [[gnu::noinline, gnu::noreturn]] void debugThrow();
113
118 [[gnu::noinline, gnu::noreturn]] void panic();
119};
120
121}
Definition args.hh:28
Definition eval-error.hh:22
friend class EvalErrorBuilder
Definition eval-error.hh:24
Definition eval-error.hh:75
friend class EvalState
Definition eval-error.hh:76
void debugThrow()
Definition eval-error.cc:81
void panic()
Definition eval-error.cc:96
Definition eval.hh:182
Definition fmt.hh:136
Definition pos-idx.hh:9
Definition suggestions.hh:26
This file defines two main structs/classes used in nix error handling.
bool addTrace
Definition lexer.l:7062
friend class EvalErrorBuilder
Definition lexer.l:5676
return s
Definition lexer.l:459
const T & value
Definition lexer.l:492
std::vector< Expr * > args
Definition lexer.l:6126
Definition eval.hh:152
Definition error.hh:80
Definition nixexpr.hh:81
Definition value.hh:167
std::string Path
Definition types.hh:22