Skip to main content

protocol_droid/domain/a2a/agent_card/
error.rs

1//! Errors the [`AgentCardBuilder`](super::AgentCardBuilder) can raise.
2//!
3//! A single enum in its own file so a `match` is greppable and a
4//! new variant does not touch the value-object file.
5
6use std::sync::Arc;
7
8use thiserror::Error;
9
10/// Errors a builder can raise.
11#[derive(Debug, Error, PartialEq, Eq)]
12pub enum AgentCardError {
13    /// `name` was empty.
14    #[error("AgentCard.name must be non-empty")]
15    EmptyName,
16    /// `description` was empty.
17    #[error("AgentCard.description must be non-empty")]
18    EmptyDescription,
19    /// `version` was empty.
20    #[error("AgentCard.version must be non-empty")]
21    EmptyVersion,
22    /// `supported_interfaces` was empty.
23    #[error("AgentCard.supported_interfaces must contain at least one interface")]
24    NoSupportedInterfaces,
25    /// `default_input_modes` was empty.
26    #[error("AgentCard.default_input_modes must contain at least one mode")]
27    NoInputModes,
28    /// `default_output_modes` was empty.
29    #[error("AgentCard.default_output_modes must contain at least one mode")]
30    NoOutputModes,
31    /// A skill was given an empty id, name, or description.
32    #[error("AgentCard.skills[{index}].{field} must be non-empty")]
33    EmptySkillField {
34        /// The skill's position in `skills`.
35        index: usize,
36        /// The empty field, one of `id`, `name`, `description`.
37        field: &'static str,
38    },
39    /// The provider's organization was empty.
40    #[error("AgentCard.provider.organization must be non-empty")]
41    EmptyProviderOrganization,
42    /// A protocol extension was given an empty uri or description.
43    #[error("AgentCard.capabilities.extensions[{index}].{field} must be non-empty")]
44    EmptyExtensionField {
45        /// The extension's position in `capabilities.extensions`.
46        index: usize,
47        /// The empty field, one of `uri`, `description`.
48        field: &'static str,
49    },
50    /// A security scheme was registered with an empty name.
51    #[error("AgentCard.security_schemes key must be non-empty")]
52    EmptySecuritySchemeName,
53    /// An API key security scheme has an empty `name` (the
54    /// parameter name, not the scheme key).
55    #[error("AgentCard.security_schemes[{name}].name must be non-empty")]
56    EmptyAPIKeyParameterName {
57        /// The scheme key in the `security_schemes` map.
58        name: Arc<str>,
59    },
60    /// An HTTP security scheme has an empty `scheme` (the
61    /// IANA-registered auth scheme, e.g. `Bearer`).
62    #[error("AgentCard.security_schemes[{name}].scheme must be non-empty")]
63    EmptyHTTPAuthScheme {
64        /// The scheme key in the `security_schemes` map.
65        name: Arc<str>,
66    },
67    /// An OAuth 2.0 security scheme has no flow set. The
68    /// proto's `oneof flow` and the `OpenAPI 3.x` wire
69    /// form both require at least one of
70    /// `authorizationCode`, `clientCredentials`, or
71    /// `deviceCode` to be present.
72    #[error("AgentCard.security_schemes[{name}].flows must declare at least one flow")]
73    EmptyOAuthFlows {
74        /// The scheme key in the `security_schemes` map.
75        name: Arc<str>,
76    },
77}