truce_rack_core/error.rs
1//! Errors surfaced by the host framework.
2//!
3//! Format wrappers also produce these; a CLAP-specific status
4//! comes back as `Error::Format { format: "clap", code, message }`
5//! rather than its own variant, so consumers can match on
6//! "did anything fail?" without enumerating per-format codes.
7
8use std::path::PathBuf;
9
10/// Result alias for rack operations.
11pub type Result<T> = std::result::Result<T, Error>;
12
13/// Top-level error type for the host framework.
14#[derive(Debug, thiserror::Error)]
15pub enum Error {
16 /// Plugin not found at the supplied path / id.
17 #[error("plugin not found: {0}")]
18 PluginNotFound(String),
19
20 /// The plugin was found but failed to load — bad signature,
21 /// missing dependency, ABI mismatch.
22 #[error("failed to load plugin at {path}: {reason}")]
23 LoadFailed {
24 /// Path the host tried to load from.
25 path: PathBuf,
26 /// Format-specific reason ("`clap_plugin_entry` returned null",
27 /// "vst3 module-info missing", etc.).
28 reason: String,
29 },
30
31 /// A plugin call returned a format-specific error code.
32 ///
33 /// `format` is the wrapper-crate short name (`"clap"`,
34 /// `"vst3"`, `"au"`, `"vst2"`, `"lv2"`, `"aax"`).
35 #[error("[{format}] {message} (code {code})")]
36 Format {
37 /// Short identifier for the format wrapper.
38 format: &'static str,
39 /// Underlying numeric status (`HRESULT` for VST3,
40 /// `OSStatus` for AU, etc.).
41 code: i64,
42 /// Human-readable description from the wrapper.
43 message: String,
44 },
45
46 /// Parameter index out of range.
47 #[error("parameter index {0} out of range")]
48 InvalidParameter(usize),
49
50 /// Method invoked before [`crate::PluginCore::activate`].
51 #[error("plugin not activated")]
52 NotActivated,
53
54 /// State blob failed deserialization.
55 #[error("state load failed: {0}")]
56 StateLoad(#[from] crate::state::StateLoadError),
57
58 /// I/O error during scan / load.
59 #[error("io error: {0}")]
60 Io(#[from] std::io::Error),
61
62 /// Plugin code panicked across the FFI boundary; caught by
63 /// [`crate::wrapper`] helpers and reported as an error rather
64 /// than aborting the host.
65 #[error("plugin {action} panicked: {message}")]
66 Panic {
67 /// Which callback was running ("process", "`save_state`", …).
68 action: &'static str,
69 /// Panic payload extracted as a string.
70 message: String,
71 },
72
73 /// Catch-all for wrapper-side bugs that don't map to a
74 /// format error code. Prefer variants over this when possible.
75 #[error("{0}")]
76 Other(String),
77}