Skip to main content

onetaskgraph_plugin_api/
error.rs

1//! The one error type every trait method returns.
2
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6/// Why a source could not answer.
7///
8/// Every variant carries owned data only, so an error survives the JSON-over-stdio
9/// boundary a subprocess-hosted plugin crosses without losing anything.
10#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, thiserror::Error)]
11#[serde(tag = "kind", rename_all = "kebab-case")]
12pub enum SourceError {
13    /// The source's configuration block is wrong, or names something absent.
14    #[error("configuration for this source is invalid: {message}")]
15    Config {
16        /// What is wrong, in a form a user can act on.
17        message: String,
18    },
19    /// The credential was missing, malformed, or rejected.
20    #[error("authentication for this source failed: {message}")]
21    Auth {
22        /// What failed. Never contains the credential itself.
23        message: String,
24    },
25    /// The source understood the request and declined it.
26    #[error("the source refused the request: {message}")]
27    Refused {
28        /// The source's own reason.
29        message: String,
30    },
31    /// The source asked the caller to slow down.
32    #[error("the source rate-limited the request")]
33    RateLimited {
34        /// How long the source asked us to wait, when it said.
35        retry_after_seconds: Option<u64>,
36    },
37    /// The source could not be reached at all.
38    #[error("the source could not be reached: {message}")]
39    Unavailable {
40        /// What went wrong reaching it.
41        message: String,
42    },
43    /// The source answered with something this interface cannot represent.
44    #[error("the source returned data this interface cannot represent: {message}")]
45    Malformed {
46        /// What could not be represented.
47        message: String,
48    },
49}