Include filename in ErrorCantOpenScriptFile.
This commit is contained in:
parent
c58b3e644a
commit
b3247204c6
@ -26,7 +26,7 @@ pub enum EvalAltResult {
|
|||||||
ErrorVariableNotFound(String),
|
ErrorVariableNotFound(String),
|
||||||
ErrorAssignmentToUnknownLHS,
|
ErrorAssignmentToUnknownLHS,
|
||||||
ErrorMismatchOutputType(String),
|
ErrorMismatchOutputType(String),
|
||||||
ErrorCantOpenScriptFile,
|
ErrorCantOpenScriptFile(String),
|
||||||
InternalErrorMalformedDotExpression,
|
InternalErrorMalformedDotExpression,
|
||||||
LoopBreak,
|
LoopBreak,
|
||||||
Return(Box<dyn Any>),
|
Return(Box<dyn Any>),
|
||||||
@ -35,6 +35,7 @@ pub enum EvalAltResult {
|
|||||||
impl EvalAltResult {
|
impl EvalAltResult {
|
||||||
fn as_str(&self) -> Option<&str> {
|
fn as_str(&self) -> Option<&str> {
|
||||||
match *self {
|
match *self {
|
||||||
|
EvalAltResult::ErrorCantOpenScriptFile(ref s) => Some(s.as_str()),
|
||||||
EvalAltResult::ErrorVariableNotFound(ref s) => Some(s.as_str()),
|
EvalAltResult::ErrorVariableNotFound(ref s) => Some(s.as_str()),
|
||||||
EvalAltResult::ErrorFunctionNotFound(ref s) => Some(s.as_str()),
|
EvalAltResult::ErrorFunctionNotFound(ref s) => Some(s.as_str()),
|
||||||
EvalAltResult::ErrorMismatchOutputType(ref s) => Some(s.as_str()),
|
EvalAltResult::ErrorMismatchOutputType(ref s) => Some(s.as_str()),
|
||||||
@ -60,7 +61,7 @@ impl PartialEq for EvalAltResult {
|
|||||||
(&ErrorVariableNotFound(ref a), &ErrorVariableNotFound(ref b)) => a == b,
|
(&ErrorVariableNotFound(ref a), &ErrorVariableNotFound(ref b)) => a == b,
|
||||||
(&ErrorAssignmentToUnknownLHS, &ErrorAssignmentToUnknownLHS) => true,
|
(&ErrorAssignmentToUnknownLHS, &ErrorAssignmentToUnknownLHS) => true,
|
||||||
(&ErrorMismatchOutputType(ref a), &ErrorMismatchOutputType(ref b)) => a == b,
|
(&ErrorMismatchOutputType(ref a), &ErrorMismatchOutputType(ref b)) => a == b,
|
||||||
(&ErrorCantOpenScriptFile, &ErrorCantOpenScriptFile) => true,
|
(&ErrorCantOpenScriptFile(ref a), &ErrorCantOpenScriptFile(ref b)) => a == b,
|
||||||
(&InternalErrorMalformedDotExpression, &InternalErrorMalformedDotExpression) => true,
|
(&InternalErrorMalformedDotExpression, &InternalErrorMalformedDotExpression) => true,
|
||||||
(&LoopBreak, &LoopBreak) => true,
|
(&LoopBreak, &LoopBreak) => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
@ -87,7 +88,7 @@ impl Error for EvalAltResult {
|
|||||||
"Assignment to an unsupported left-hand side"
|
"Assignment to an unsupported left-hand side"
|
||||||
}
|
}
|
||||||
EvalAltResult::ErrorMismatchOutputType(_) => "Cast of output failed",
|
EvalAltResult::ErrorMismatchOutputType(_) => "Cast of output failed",
|
||||||
EvalAltResult::ErrorCantOpenScriptFile => "Cannot open script file",
|
EvalAltResult::ErrorCantOpenScriptFile(_) => "Cannot open script file",
|
||||||
EvalAltResult::InternalErrorMalformedDotExpression => {
|
EvalAltResult::InternalErrorMalformedDotExpression => {
|
||||||
"[Internal error] Unexpected expression in dot expression"
|
"[Internal error] Unexpected expression in dot expression"
|
||||||
}
|
}
|
||||||
@ -710,10 +711,10 @@ impl Engine {
|
|||||||
if f.read_to_string(&mut contents).is_ok() {
|
if f.read_to_string(&mut contents).is_ok() {
|
||||||
self.eval::<T>(&contents)
|
self.eval::<T>(&contents)
|
||||||
} else {
|
} else {
|
||||||
Err(EvalAltResult::ErrorCantOpenScriptFile)
|
Err(EvalAltResult::ErrorCantOpenScriptFile(fname.to_owned()))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Err(EvalAltResult::ErrorCantOpenScriptFile)
|
Err(EvalAltResult::ErrorCantOpenScriptFile(fname.to_owned()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -786,10 +787,10 @@ impl Engine {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Err(EvalAltResult::ErrorCantOpenScriptFile)
|
Err(EvalAltResult::ErrorCantOpenScriptFile(fname.to_owned()))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Err(EvalAltResult::ErrorCantOpenScriptFile)
|
Err(EvalAltResult::ErrorCantOpenScriptFile(fname.to_owned()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -800,7 +801,7 @@ impl Engine {
|
|||||||
self.consume_with_scope(&mut Scope::new(), input)
|
self.consume_with_scope(&mut Scope::new(), input)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Evaluate a string with own scoppe, but only return errors, if there are any.
|
/// Evaluate a string with own scope, but only return errors, if there are any.
|
||||||
/// Useful for when you don't need the result, but still need
|
/// Useful for when you don't need the result, but still need
|
||||||
/// to keep track of possible errors
|
/// to keep track of possible errors
|
||||||
pub fn consume_with_scope(
|
pub fn consume_with_scope(
|
||||||
@ -842,7 +843,7 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Register the default library. That means, numberic types, char, bool
|
/// Register the default library. That means, numeric types, char, bool
|
||||||
/// String, arithmetics and string concatenations.
|
/// String, arithmetics and string concatenations.
|
||||||
pub fn register_default_lib(engine: &mut Engine) {
|
pub fn register_default_lib(engine: &mut Engine) {
|
||||||
macro_rules! reg_op {
|
macro_rules! reg_op {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user