add more graceful errors (w/ stacktrace) to stdlib

This commit is contained in:
Mark
2024-06-20 15:52:57 +02:00
parent 9e7bbc110e
commit f59c0941f5
6 changed files with 26 additions and 24 deletions

View File

@@ -93,7 +93,7 @@ impl Config {
} else if let Some(data::float::Float(n)) = a.as_any().downcast_ref() {
Duration::from_secs_f64(*n)
} else {
unreachable!("sleep called on non-int/non-float")
return Err("sleep called on non-int/non-float".into());
});
Ok(Data::empty_tuple())
}),
@@ -154,7 +154,7 @@ impl Config {
// -1 if more elements than isize can represent
i.take(isize::MAX as usize + 1).count() as isize
} else {
unreachable!("called len on {a:?}, which isn't a tuple or a string")
return Err("called len on {a:?}, which isn't a tuple or a string".into());
})))
}),
inner_statements: None,
@@ -394,7 +394,7 @@ impl Config {
// return func.run(arg.clone());
// }
// }
// unreachable!("try: no function found")
// unreacha ble!("try: no function found")
// }),
// inner_statements: None,
// })

View File

@@ -97,15 +97,15 @@ impl Config {
}
Ok(Data::empty_tuple())
} else {
unreachable!(
"for_each called on tuple not containing iterable and function"
)
return Err(
"for_each called on tuple not containing iterable and function".into()
);
}
} else {
unreachable!("for_each called on tuple with len < 2")
return Err("for_each called on tuple with len < 2".into());
}
} else {
unreachable!("for_each called on non-tuple")
return Err("for_each called on non-tuple".into());
}
}),
inner_statements: None,
@@ -223,13 +223,13 @@ fn genfunc_iter_and_arg<T: MersType, D: MersData>(
if let Some(f) = f.get().as_any().downcast_ref::<D>() {
Ok(Data::new(Iter(fd(f), v.clone())))
} else {
unreachable!("{name} called on tuple not containing function")
return Err("{name} called on tuple not containing function".into());
}
} else {
unreachable!("{name} called on tuple with len < 2")
return Err("{name} called on tuple with len < 2".into());
}
} else {
unreachable!("{name} called on non-tuple")
return Err("{name} called on non-tuple".into());
}
}),
inner_statements: None,

View File

@@ -123,7 +123,7 @@ impl Config {
-1
} else { 0
}
} else { unreachable!("called signum on non-number type")})))
} else { return Err("called signum on non-number type".into()); })))
}),
inner_statements: None,
})) .add_var("div".to_string(), Data::new(data::function::Function {
@@ -141,9 +141,9 @@ impl Config {
(Some(data::int::Int(l)), None, None, Some(data::float::Float(r))) => Ok(Data::new(data::float::Float(*l as f64 / r))),
(None, Some(data::float::Float(l)), Some(data::int::Int(r)), None) => Ok(Data::new(data::float::Float(l / *r as f64))),
(None, Some(data::float::Float(l)), None, Some(data::float::Float(r))) => Ok(Data::new(data::float::Float(l / r))),
_ => unreachable!(),
_ => return Err("at least one of the arguments to div were neither an int nor a float".into()),
}
} else { unreachable!() }),
} else { return Err("argument to div was not a tuple".into()); }),
inner_statements: None,
})).add_var("modulo".to_string(), Data::new(data::function::Function {
info: Arc::new(program::run::Info::neverused()),
@@ -160,9 +160,9 @@ impl Config {
(Some(data::int::Int(l)), None, None, Some(data::float::Float(r))) => Ok(Data::new(data::float::Float(*l as f64 % r))),
(None, Some(data::float::Float(l)), Some(data::int::Int(r)), None) => Ok(Data::new(data::float::Float(l % *r as f64))),
(None, Some(data::float::Float(l)), None, Some(data::float::Float(r))) => Ok(Data::new(data::float::Float(l % r))),
_ => unreachable!(),
_ => return Err("at least one of the arguments to modulo were neither an int nor a float".into()),
}
} else { unreachable!() }),
} else { return Err("argument to modulo was not a tuple".into()) }),
inner_statements: None,
}))
.add_var(
@@ -223,7 +223,7 @@ impl Config {
Data::new(data::int::Int(sumi))
})
} else {
unreachable!("sum called on non-tuple")
return Err("sum called on non-tuple".into());
}
}),
inner_statements: None,
@@ -298,7 +298,7 @@ impl Config {
Data::new(data::int::Int(sumi))
})
} else {
unreachable!("sum called on non-tuple")
return Err("sum called on non-tuple".into());
}
}),
inner_statements: None,
@@ -362,7 +362,7 @@ impl Config {
Data::new(data::int::Int(prodi))
})
} else {
unreachable!("product called on non-tuple")
return Err("product called on non-tuple".into());
}
}),
inner_statements: None,
@@ -436,7 +436,9 @@ fn ltgtoe_function(
} else if let Some(data::float::Float(v)) = item.as_any().downcast_ref() {
IntOrFloatOrNothing::Float(*v)
} else {
unreachable!()
return Err(
"one of the (l/g)t[oe] function argument iterator elements were neither int nor float".into(),
);
};
if op(prev, new) {
prev = new;

View File

@@ -57,7 +57,7 @@ impl Config {
move || f.run(Data::empty_tuple()),
)))))))
} else {
unreachable!("thread called, but arg wasn't a function");
return Err("thread called, but arg wasn't a function".into());
}
}),
inner_statements: None,