git.delta.rocks / jrsonnet / refs/commits / 38dfcbef8382

difftreelog

source

crates/jrsonnet-evaluator/src/error.rs2.1 KiBsourcehistory
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>),3637	FieldMustBeStringGot(ValType),3839	AttemptedIndexAnArrayWithString(Rc<str>),40	ValueIndexMustBeTypeGot(ValType, ValType, ValType),41	CantIndexInto(ValType),4243	StandaloneSuper,4445	ImportFileNotFound(PathBuf, PathBuf),46	ResolvedFileNotFound(PathBuf),47	ImportBadFileUtf8(PathBuf),48	ImportNotSupported(PathBuf, PathBuf),49	ImportSyntaxError {50		path: Rc<PathBuf>,51		source_code: Rc<str>,52		error: jrsonnet_parser::ParseError,53	},5455	RuntimeError(Rc<str>),56	StackOverflow,57	FractionalIndex,58	DivisionByZero,5960	StringManifestOutputIsNotAString,6162	ImportCallbackError(String),63	InvalidUnicodeCodepointGot(u32),6465	Format(FormatError),66}67impl From<Error> for LocError {68	fn from(e: Error) -> Self {69		Self(e, StackTrace(vec![]))70	}71}7273#[derive(Clone, Debug)]74pub struct StackTraceElement {75	pub location: ExprLocation,76	pub desc: String,77}78#[derive(Debug, Clone)]79pub struct StackTrace(pub Vec<StackTraceElement>);8081#[derive(Debug, Clone)]82pub struct LocError(pub Error, pub StackTrace);83impl LocError {84	pub fn new(e: Error) -> Self {85		Self(e, StackTrace(vec![]))86	}87}8889pub type Result<V> = std::result::Result<V, LocError>;9091#[macro_export]92macro_rules! throw {93	($e: expr) => {94		return Err($e.into());95	};96}