1use tan::{
2 context::Context,
3 error::Error,
4 expr::Expr,
5 util::{
6 args::{unpack_arg, unpack_stringable_arg},
7 module_util::require_module,
8 },
9};
10
11fn error_new(args: &[Expr]) -> Result<Expr, Error> {
16 let reason = unpack_stringable_arg(args, 0, "reason")?;
17 Ok(Expr::error(reason))
18}
19
20fn is_error(args: &[Expr]) -> Result<Expr, Error> {
21 let arg = unpack_arg(args, 0, "value")?;
22 if let Expr::Error(_) = arg {
23 Ok(Expr::Bool(true))
24 } else {
25 Ok(Expr::Bool(false))
26 }
27}
28
29pub fn setup_lib_error(context: &mut Context) {
30 let module = require_module("prelude", context);
32
33 module.insert_invocable("Error", Expr::foreign_func(&error_new));
35 module.insert_invocable("is-error?", Expr::foreign_func(&is_error));
37}