Skip to main content

wickra_terminal_core/
error.rs

1//! The crate error type.
2//!
3//! Everything fallible in the core — parsing a config, decoding a command,
4//! building a source — funnels into [`Error`], so the data-driven FFI boundary
5//! (`Terminal::command_json`) can turn any failure into a typed message instead
6//! of a panic across the C ABI.
7
8use thiserror::Error;
9
10/// An error raised by the terminal core.
11#[derive(Debug, Error)]
12pub enum Error {
13    /// The config could not be parsed (TOML or JSON).
14    #[error("invalid config: {0}")]
15    Config(String),
16
17    /// A command JSON string could not be decoded into a known command.
18    #[error("invalid command: {0}")]
19    Command(String),
20
21    /// A source spec referred to something that could not be built (e.g. an
22    /// unknown venue, or a replay dataset that failed to load).
23    #[error("invalid source: {0}")]
24    Source(String),
25
26    /// No source is registered under the given id.
27    #[error("unknown source id: {0}")]
28    UnknownSource(u32),
29
30    /// A JSON (de)serialization error on the command/frame boundary.
31    #[error("json error: {0}")]
32    Json(#[from] serde_json::Error),
33
34    /// An error surfaced by the underlying exchange connectivity layer.
35    #[error("exchange error: {0}")]
36    Exchange(String),
37}
38
39/// The crate result alias.
40pub type Result<T> = core::result::Result<T, Error>;