//! 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", } } }