Skip to main content

linkrs_query/executor/expression/functions/udf/
error.rs

1//! UDF error type.
2
3use crate::executor::expression::{ExpressionError, ExpressionErrorType};
4use thiserror::Error;
5
6/// Errors raised while loading, unloading, or executing dynamic UDFs.
7#[derive(Error, Debug, Clone, PartialEq)]
8pub enum UdfError {
9    #[error("invalid library path '{0}': {1}")]
10    InvalidPath(String, String),
11
12    #[error("failed to load library '{0}': {1}")]
13    LibraryLoad(String, String),
14
15    #[error("symbol '{1}' not found in library '{0}'")]
16    SymbolNotFound(String, String),
17
18    #[error("plugin factory in '{0}' returned a null pointer")]
19    NullPlugin(String),
20
21    #[error("plugin in '{0}' reports an empty function name")]
22    InvalidName(String),
23
24    #[error("function '{0}' is already loaded from '{1}'")]
25    AlreadyLoaded(String, String),
26
27    #[error("no dynamic function loaded under name '{0}'")]
28    NotLoaded(String),
29
30    #[error("function name '{0}' conflicts with a builtin function")]
31    BuiltinConflict(String),
32
33    #[error("plugin '{0}' ABI version mismatch: expected {1}, got {2}")]
34    VersionMismatch(String, u32, u32),
35
36    #[error("dynamic function '{0}' panicked and was isolated: {1}")]
37    ExecutionPanic(String, String),
38
39    #[error("remote extension sources are not supported yet: '{0}'")]
40    RepoDownloadUnsupported(String),
41
42    #[error("io error for '{0}': {1}")]
43    Io(String, String),
44}
45
46impl UdfError {
47    /// Map the error into an expression-level error for query execution.
48    pub fn to_expression_error(&self) -> ExpressionError {
49        let error_type = match self {
50            UdfError::ExecutionPanic(_, _) => ExpressionErrorType::FunctionExecutionError,
51            UdfError::NotLoaded(_) => ExpressionErrorType::UndefinedFunction,
52            _ => ExpressionErrorType::InvalidOperation,
53        };
54        ExpressionError::new(error_type, self.to_string())
55    }
56}