git.delta.rocks / jrsonnet / refs/commits / d4ade76b40aa

difftreelog

fix(evaluator) handle rest of panics as errors

Лач2020-06-27parent: #7eb3214.patch.diff
in: master

3 files changed

modifiedcrates/jsonnet-evaluator/src/error.rsdiffbeforeafterboth
1use crate::ValType;1use crate::{Val, ValType};
2use jsonnet_parser::{BinaryOpType, ExprLocation, UnaryOpType};2use jsonnet_parser::{BinaryOpType, ExprLocation, UnaryOpType};
3use std::{path::PathBuf, rc::Rc};3use std::{path::PathBuf, rc::Rc};
44
10 UnaryOperatorDoesNotOperateOnType(UnaryOpType, ValType),10 UnaryOperatorDoesNotOperateOnType(UnaryOpType, ValType),
11 BinaryOperatorDoesNotOperateOnValues(BinaryOpType, ValType, ValType),11 BinaryOperatorDoesNotOperateOnValues(BinaryOpType, ValType, ValType),
12
13 NoTopLevelObjectFound,
14 CantUseSelfOutsideOfObject,
15 CantUseSuperOutsideOfObject,
16
17 InComprehensionCanOnlyIterateOverArray,
18
19 ArrayBoundsError(usize, usize),
20
21 AssertionFailed(Val),
1222
13 VariableIsNotDefined(String),23 VariableIsNotDefined(String),
14 TypeMismatch(&'static str, Vec<ValType>, ValType),24 TypeMismatch(&'static str, Vec<ValType>, ValType),
modifiedcrates/jsonnet-evaluator/src/evaluate.rsdiffbeforeafterboth
207 }207 }
208 Some(out.into_iter().flatten().flatten().collect())208 Some(out.into_iter().flatten().flatten().collect())
209 }209 }
210 _ => panic!("for expression evaluated to non-iterable value"),210 _ => create_error_result(Error::InComprehensionCanOnlyIterateOverArray)?,
211 }211 }
212 }212 }
213 })213 })
384 context384 context
385 .this()385 .this()
386 .clone()386 .clone()
387 .unwrap_or_else(|| panic!("this not found")),387 .ok_or_else(|| create_error(crate::Error::CantUseSelfOutsideOfObject))?,
388 ),388 ),
389 Literal(LiteralType::Dollar) => Val::Obj(389 Literal(LiteralType::Dollar) => Val::Obj(
390 context390 context
391 .dollar()391 .dollar()
392 .clone()392 .clone()
393 .unwrap_or_else(|| panic!("dollar not found")),393 .ok_or_else(|| create_error(crate::Error::NoTopLevelObjectFound))?,
394 ),394 ),
395 Literal(LiteralType::True) => Val::Bool(true),395 Literal(LiteralType::True) => Val::Bool(true),
396 Literal(LiteralType::False) => Val::Bool(false),396 Literal(LiteralType::False) => Val::Bool(false),
682 out.reserve(items.len());682 out.reserve(items.len());
683 out.extend(items.iter().cloned());683 out.extend(items.iter().cloned());
684 } else {684 } else {
685 panic!("all array items should be arrays")685 create_error_result(crate::Error::RuntimeError("in std.join all items should be arrays".into()))?;
686 }686 }
687 }687 }
688688
700 first = false;700 first = false;
701 out += &item;701 out += &item;
702 } else {702 } else {
703 panic!("all array items should be strings")703 create_error_result(crate::Error::RuntimeError("in std.join all items should be strings".into()))?;
704 }704 }
705 }705 }
706706
753 if assertion_result {753 if assertion_result {
754 evaluate(context, returned)?754 evaluate(context, returned)?
755 } else if let Some(msg) = msg {755 } else if let Some(msg) = msg {
756 panic!(756 create_error_result(crate::Error::AssertionFailed(evaluate(context, msg)?))?
757 "assertion failed ({:?}): {}",
758 value,
759 evaluate(context, msg)?.try_cast_str("assertion message should be string")?
760 );
761 } else {757 } else {
762 panic!("assertion failed ({:?}): no message", value);758 create_error_result(crate::Error::AssertionFailed(Val::Null))?
763 }759 }
764 }760 }
765 Error(e) => create_error_result(crate::Error::RuntimeError(761 Error(e) => create_error_result(crate::Error::RuntimeError(
modifiedcrates/jsonnet-evaluator/src/val.rsdiffbeforeafterboth
265 buf.push_str(cur_padding);265 buf.push_str(cur_padding);
266 buf.push('}');266 buf.push('}');
267 }267 }
268 Val::Func(_) | Val::Intristic(_, _) => panic!("tried to manifest function"),268 Val::Func(_) | Val::Intristic(_, _) => create_error_result(Error::RuntimeError("tried to manifest function".into()))?,
269 Val::Lazy(_) => unreachable!(),269 Val::Lazy(_) => unreachable!(),
270 };270 };
271 Ok(())271 Ok(())