2022-08-04 16:43:51 +03:00
|
|
|
use std::fmt::Display;
|
|
|
|
|
2022-08-22 23:48:47 +03:00
|
|
|
#[derive(Clone, Debug)]
|
2022-08-22 23:20:50 +03:00
|
|
|
pub enum ErrorKind {
|
2022-08-09 18:56:21 +03:00
|
|
|
DuplicateAttrsKey {
|
|
|
|
key: String,
|
|
|
|
},
|
|
|
|
|
2022-08-11 15:29:11 +03:00
|
|
|
AttributeNotFound {
|
|
|
|
name: String,
|
|
|
|
},
|
|
|
|
|
2022-08-08 02:16:02 +03:00
|
|
|
TypeError {
|
|
|
|
expected: &'static str,
|
|
|
|
actual: &'static str,
|
|
|
|
},
|
2022-08-11 11:37:04 +03:00
|
|
|
|
|
|
|
Incomparable {
|
|
|
|
lhs: &'static str,
|
|
|
|
rhs: &'static str,
|
|
|
|
},
|
2022-08-12 18:12:28 +03:00
|
|
|
|
|
|
|
// Resolving a user-supplied path literal failed in some way.
|
|
|
|
PathResolution(String),
|
2022-08-13 19:42:50 +03:00
|
|
|
|
|
|
|
// Dynamic keys are not allowed in let.
|
|
|
|
DynamicKeyInLet(rnix::SyntaxNode),
|
2022-08-13 20:17:25 +03:00
|
|
|
|
|
|
|
// Unknown variable in statically known scope.
|
2022-08-22 23:48:47 +03:00
|
|
|
UnknownStaticVariable,
|
2022-08-15 01:13:17 +03:00
|
|
|
|
|
|
|
// Unknown variable in dynamic scope (with, rec, ...).
|
|
|
|
UnknownDynamicVariable(String),
|
2022-08-15 01:47:30 +03:00
|
|
|
|
2022-08-27 17:16:46 +03:00
|
|
|
// User is defining the same variable twice at the same depth.
|
|
|
|
VariableAlreadyDefined(String),
|
|
|
|
|
2022-08-24 02:26:58 +03:00
|
|
|
// Attempt to call something that is not callable.
|
|
|
|
NotCallable,
|
|
|
|
|
2022-08-29 18:33:02 +03:00
|
|
|
// Infinite recursion encountered while forcing thunks.
|
|
|
|
InfiniteRecursion,
|
|
|
|
|
2022-08-15 01:47:30 +03:00
|
|
|
ParseErrors(Vec<rnix::parser::ParseError>),
|
2022-08-16 15:53:35 +03:00
|
|
|
|
|
|
|
AssertionFailed,
|
2022-08-24 17:13:00 +03:00
|
|
|
|
|
|
|
// These are user-generated errors through builtins.
|
|
|
|
Throw(String),
|
|
|
|
Abort(String),
|
2022-09-02 00:13:30 +03:00
|
|
|
|
|
|
|
// An error occured while forcing a thunk, and needs to be chained
|
|
|
|
// up.
|
|
|
|
ThunkForce(Box<Error>),
|
2022-08-08 02:16:02 +03:00
|
|
|
}
|
2022-08-04 16:43:51 +03:00
|
|
|
|
2022-08-22 23:48:47 +03:00
|
|
|
#[derive(Clone, Debug)]
|
2022-08-22 23:20:50 +03:00
|
|
|
pub struct Error {
|
|
|
|
pub kind: ErrorKind,
|
2022-09-01 23:50:27 +03:00
|
|
|
pub span: codemap::Span,
|
2022-08-22 23:20:50 +03:00
|
|
|
}
|
|
|
|
|
2022-08-04 16:43:51 +03:00
|
|
|
impl Display for Error {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
2022-08-22 23:20:50 +03:00
|
|
|
writeln!(f, "{:?}", self.kind)
|
2022-08-04 16:43:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub type EvalResult<T> = Result<T, Error>;
|