File size: 1,552 Bytes
3374e90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! Error types for bex-js.

use thiserror::Error;

#[derive(Error, Debug)]
pub enum JsError {
    #[error("JS syntax error: {0}")]
    Syntax(String),

    #[error("JS runtime error: {0}")]
    Runtime(String),

    #[error("JS evaluation timed out after {0}ms")]
    Timeout(u32),

    #[error("JS out of memory (limit: {0}MB)")]
    OutOfMemory(u32),

    #[error("JS execution error: {0}")]
    Execution(String),

    #[error("JS pool busy — all workers occupied")]
    PoolBusy,

    #[error("JS pool shut down")]
    PoolShutdown,

    #[error("Function not found: {0}")]
    FunctionNotFound(String),

    #[error("JS permission denied: {0}")]
    PermissionDenied(String),

    #[error("Invalid JSON argument: {0}")]
    InvalidJson(String),

    #[error("Internal JS error: {0}")]
    Internal(String),
}

impl JsError {
    /// Convert to a human-readable error type string for WIT plugin-error mapping.
    pub fn error_kind(&self) -> &'static str {
        match self {
            JsError::Syntax(_) => "syntax",
            JsError::Runtime(_) => "runtime",
            JsError::Timeout(_) => "timeout",
            JsError::OutOfMemory(_) => "oom",
            JsError::Execution(_) => "execution",
            JsError::PoolBusy => "pool_busy",
            JsError::PoolShutdown => "pool_shutdown",
            JsError::FunctionNotFound(_) => "fn_not_found",
            JsError::PermissionDenied(_) => "denied",
            JsError::InvalidJson(_) => "invalid_json",
            JsError::Internal(_) => "internal",
        }
    }
}