datadog_agent_remote_config/error.rs
1use std::fmt;
2
3/// A result produced by the remote configuration client.
4pub type Result<T> = std::result::Result<T, Error>;
5
6/// An error produced by the remote configuration client.
7#[derive(Debug)]
8#[non_exhaustive]
9pub enum Error {
10 /// The product already has a live subscription on this client.
11 ///
12 /// A product carries one apply status per configuration, so only one subscriber may decode it. To drive several
13 /// consumers from one product, subscribe once where those consumers are wired together and give each of them a
14 /// clone of that [`Subscription`](crate::Subscription): every clone observes the latest snapshot, and the product
15 /// is still decoded once per snapshot.
16 ///
17 /// The client does not return the existing subscription, because it cannot know that the type the second caller
18 /// asks for is the type the first caller subscribed with. This error therefore means the call sites need
19 /// restructuring so that one of them owns the subscription and passes clones to the others, rather than that the
20 /// call should be retried.
21 AlreadySubscribed {
22 /// The name of the product that is already subscribed, such as `APM_SEMANTIC_CORE_DD`.
23 product: String,
24 },
25
26 /// A field of [`RcClientConfiguration`](crate::RcClientConfiguration) is out of range.
27 InvalidSettings {
28 /// Which field is out of range, its bound, and the value it was given.
29 message: String,
30 },
31}
32
33impl fmt::Display for Error {
34 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
35 match self {
36 Self::AlreadySubscribed { product } => write!(f, "Product {product} is already subscribed on this client."),
37 Self::InvalidSettings { message } => f.write_str(message),
38 }
39 }
40}
41
42impl std::error::Error for Error {}
43
44/// Converts a subscriber's decoding error into a rejection message for the Agent.
45///
46/// The protocol carries an apply error as a string, not an error category. Choose a message that identifies the
47/// problem without including secrets or raw configuration payloads. A [`decode`](crate::ProductDecoder::decode) error
48/// rejects that configuration alone; a [`build`](crate::ProductDecoder::build) error rejects every configuration that
49/// decoded successfully.
50pub trait ApplyError {
51 /// Describes this error as a rejection the client can report to the Agent.
52 fn apply_error(&self) -> String;
53}
54
55impl ApplyError for String {
56 fn apply_error(&self) -> String {
57 self.clone()
58 }
59}