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)]
19#[non_exhaustive]
20pub enum PluginError {
21    #[error("invalid input: {0}")]
22    InvalidInput(String),
23    #[error("validation errors: {0:?}")]
24    ValidationErrors(Vec<PluginFieldError>),
25    #[error("calculation failed: {0}")]
26    Calculation(String),
27    #[error("product_group not supported by this plugin: {0}")]
28    UnsupportedProductGroup(String),
29    #[error("schema version not supported: {0}")]
30    UnsupportedSchemaVersion(String),
31    #[error("capability not available: {0}")]
32    CapabilityNotAvailable(String),
33    #[error("internal plugin error: {0}")]
34    Internal(String),
35}