Skip to main content

xript_runtime/
error.rs

1use thiserror::Error;
2
3#[derive(Debug, Error)]
4pub enum XriptError {
5    #[error("invalid xript manifest:\n{}", format_issues(.issues))]
6    ManifestValidation { issues: Vec<ValidationIssue> },
7
8    #[error("binding error in `{binding}`: {message}")]
9    Binding { binding: String, message: String },
10
11    #[error("`{binding}()` requires the \"{capability}\" capability, which hasn't been granted to this script")]
12    CapabilityDenied { binding: String, capability: String },
13
14    #[error("execution limit exceeded: {limit}")]
15    ExecutionLimit { limit: String },
16
17    #[error("script error: {0}")]
18    Script(String),
19
20    #[error("mod entry script error in `{mod_name}`: {message}")]
21    ModEntry { mod_name: String, message: String },
22
23    #[error("QuickJS error: {0}")]
24    Engine(String),
25
26    #[error("JSON error: {0}")]
27    Json(#[from] serde_json::Error),
28
29    #[error("IO error: {0}")]
30    Io(#[from] std::io::Error),
31}
32
33#[derive(Debug, Clone)]
34pub struct ValidationIssue {
35    pub path: String,
36    pub message: String,
37}
38
39fn format_issues(issues: &[ValidationIssue]) -> String {
40    issues
41        .iter()
42        .map(|i| format!("  {}: {}", i.path, i.message))
43        .collect::<Vec<_>>()
44        .join("\n")
45}
46
47pub type Result<T> = std::result::Result<T, XriptError>;