1use crate::{builtin::format::FormatError, Val, ValType};2use jrsonnet_parser::{BinaryOpType, ExprLocation, UnaryOpType};3use std::{path::PathBuf, rc::Rc};45#[derive(Debug, Clone)]6pub enum Error {7 IntristicNotFound(Rc<str>, Rc<str>),8 IntristicArgumentReorderingIsNotSupportedYet,910 UnaryOperatorDoesNotOperateOnType(UnaryOpType, ValType),11 BinaryOperatorDoesNotOperateOnValues(BinaryOpType, ValType, ValType),1213 NoTopLevelObjectFound,14 CantUseSelfOutsideOfObject,15 CantUseSuperOutsideOfObject,1617 InComprehensionCanOnlyIterateOverArray,1819 ArrayBoundsError(usize, usize),2021 AssertionFailed(Val),2223 VariableIsNotDefined(String),24 TypeMismatch(&'static str, Vec<ValType>, ValType),25 NoSuchField(Rc<str>),2627 UnknownVariable(Rc<str>),2829 OnlyFunctionsCanBeCalledGot(ValType),30 UnknownFunctionParameter(String),31 BindingParameterASecondTime(Rc<str>),32 TooManyArgsFunctionHas(usize),33 FunctionParameterNotBoundInCall(Rc<str>),3435 UndefinedExternalVariable(Rc<str>),36 UndefinedExternalFunction(Rc<str>),3738 FieldMustBeStringGot(ValType),3940 AttemptedIndexAnArrayWithString(Rc<str>),41 ValueIndexMustBeTypeGot(ValType, ValType, ValType),42 CantIndexInto(ValType),4344 StandaloneSuper,4546 ImportFileNotFound(PathBuf, PathBuf),47 ResolvedFileNotFound(PathBuf),48 ImportBadFileUtf8(PathBuf),49 ImportNotSupported(PathBuf, PathBuf),50 ImportSyntaxError {51 path: Rc<PathBuf>,52 source_code: Rc<str>,53 error: jrsonnet_parser::ParseError,54 },5556 RuntimeError(Rc<str>),57 StackOverflow,58 FractionalIndex,59 DivisionByZero,6061 StringManifestOutputIsNotAString,62 StreamManifestOutputIsNotAArray,63 MultiManifestOutputIsNotAObject,6465 StreamManifestOutputCannotBeRecursed,66 StreamManifestCannotNestString,6768 ImportCallbackError(String),69 InvalidUnicodeCodepointGot(u32),7071 Format(FormatError),72}73impl From<Error> for LocError {74 fn from(e: Error) -> Self {75 Self(e, StackTrace(vec![]))76 }77}7879#[derive(Clone, Debug)]80pub struct StackTraceElement {81 pub location: ExprLocation,82 pub desc: String,83}84#[derive(Debug, Clone)]85pub struct StackTrace(pub Vec<StackTraceElement>);8687#[derive(Debug, Clone)]88pub struct LocError(pub Error, pub StackTrace);89impl LocError {90 pub fn new(e: Error) -> Self {91 Self(e, StackTrace(vec![]))92 }93}9495pub type Result<V> = std::result::Result<V, LocError>;9697#[macro_export]98macro_rules! throw {99 ($e: expr) => {100 return Err($e.into());101 };102}