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