Skip to main content

dpp_plugin_traits/
error.rs

1//! Plugin error types: [`PluginError`] and its field-level detail [`PluginFieldError`].
2
3use serde::{Deserialize, Serialize};
4use thiserror::Error;
5
6/// Structured error with field-level detail.
7#[derive(Debug, Clone, Serialize, Deserialize)]
8#[serde(rename_all = "camelCase")]
9pub struct PluginFieldError {
10    /// JSON pointer to the failing field, e.g. `"/fibreComposition/0/pct"`.
11    pub field: String,
12    /// Error code for programmatic handling (e.g. `"out_of_range"`, `"missing"`).
13    pub code: String,
14    /// Human-readable error message.
15    pub message: String,
16}
17
18#[derive(Debug, Clone, Error, Serialize, Deserialize)]
19pub enum PluginError {
20    #[error("invalid input: {0}")]
21    InvalidInput(String),
22    #[error("validation errors: {0:?}")]
23    ValidationErrors(Vec<PluginFieldError>),
24    #[error("calculation failed: {0}")]
25    Calculation(String),
26    #[error("sector not supported by this plugin: {0}")]
27    UnsupportedSector(String),
28    #[error("schema version not supported: {0}")]
29    UnsupportedSchemaVersion(String),
30    #[error("capability not available: {0}")]
31    CapabilityNotAvailable(String),
32    #[error("internal plugin error: {0}")]
33    Internal(String),
34}