use endbasic_core::*;
use std::rc::Rc;
pub(super) struct LastErrorFunction {
metadata: Rc<CallableMetadata>,
}
impl LastErrorFunction {
pub(super) fn new() -> Rc<Self> {
Rc::from(Self {
metadata: CallableMetadataBuilder::new("LAST_ERROR")
.with_return_type(ExprType::Text)
.with_syntax(&[(&[], None)])
.test_build(),
})
}
}
impl Callable for LastErrorFunction {
fn metadata(&self) -> Rc<CallableMetadata> {
self.metadata.clone()
}
fn exec(&self, scope: Scope<'_>) -> CallResult<()> {
let last_error = scope
.last_error()
.map(|(pos, message)| format!("{}: {}", pos, message))
.unwrap_or_default();
scope.return_string(last_error)
}
}