Skip to main content

dkp_core/
error.rs

1use std::path::PathBuf;
2use thiserror::Error;
3
4#[derive(Debug, Error)]
5pub enum DkpError {
6    // Pack loading
7    #[error("pack not found: {0}")]
8    PackNotFound(PathBuf),
9
10    #[error("manifest.json missing from pack at {0}")]
11    ManifestMissing(PathBuf),
12
13    #[error("manifest.json invalid: {reason}")]
14    ManifestInvalid { reason: String },
15
16    #[error("required field '{field}' missing or empty in manifest.json")]
17    ManifestFieldMissing { field: &'static str },
18
19    // Asset parsing
20    #[error("failed to parse {asset}: {source}")]
21    AssetParse {
22        asset: String,
23        #[source]
24        source: serde_json::Error,
25    },
26
27    #[error("invalid JSONL in {file} at line {line}: {reason}")]
28    JsonlParse {
29        file: String,
30        line: usize,
31        reason: String,
32    },
33
34    #[error("schema validation failed for {asset}: {violations}")]
35    SchemaValidation { asset: String, violations: String },
36
37    // Search
38    #[error("search index error: {0}")]
39    SearchIndex(String),
40
41    // Validation gates
42    #[error("gate {gate} failed: {reason}")]
43    GateFailed { gate: u8, reason: String },
44
45    // OKF
46    #[error("OKF frontmatter error in {file}: {reason}")]
47    OkfFrontmatter { file: String, reason: String },
48
49    #[error("broken OKF link in {file}: target '{target}' not found")]
50    OkfBrokenLink { file: String, target: String },
51
52    // Evidence
53    #[error("source_ref '{source_ref}' in {asset} does not resolve to sources.csv")]
54    UnresolvedSourceRef { source_ref: String, asset: String },
55
56    // Archive
57    #[error("archive error: {0}")]
58    Archive(String),
59
60    // Config
61    #[error("config error: {0}")]
62    Config(String),
63
64    // Procedures
65    #[error("procedure '{id}' not found in pack '{pack}'")]
66    ProcedureNotFound { id: String, pack: String },
67
68    #[error("procedure '{id}' has no executable (.wasm absent, no entry_point declared)")]
69    ProcedureNoExecutable { id: String },
70
71    #[error("procedure '{id}' exceeded {limit_ms}ms wall-clock timeout")]
72    ProcedureTimeout { id: String, limit_ms: u64 },
73
74    #[error("procedure '{id}' produced invalid JSON output: {reason}")]
75    ProcedureInvalidOutput { id: String, reason: String },
76
77    #[error("procedure '{id}' trapped during execution: {message}")]
78    ProcedureTrap { id: String, message: String },
79
80    #[error("cannot satisfy procedure_capabilities constraint '{constraint}' for '{id}'")]
81    ProcedureConstraintUnsatisfied { id: String, constraint: String },
82
83    #[error("procedure schema '{id}' is not valid JSON Schema: {message}")]
84    ProcedureSchemaInvalid { id: String, message: String },
85
86    #[error("procedure '{id}' is a non-WASM executable and cannot be run from an unsigned bundle (pass --allow-unsigned to override)")]
87    ProcedureUnsignedSubprocess { id: String },
88
89    // Registry
90    #[error("registry error: {0}")]
91    Registry(String),
92
93    // Pass-through
94    #[error("IO error: {0}")]
95    Io(#[from] std::io::Error),
96
97    #[error("JSON error: {0}")]
98    Json(#[from] serde_json::Error),
99}
100
101pub type DkpResult<T> = Result<T, DkpError>;