scconfig_rs/error.rs
1use std::string::FromUtf8Error;
2
3use reqwest::StatusCode;
4use thiserror::Error;
5
6/// Result type used by this crate.
7pub type Result<T> = std::result::Result<T, Error>;
8
9/// Error type returned by the Spring Cloud Config client.
10#[derive(Debug, Error)]
11pub enum Error {
12 /// The base URL could not be parsed.
13 #[error("base URL is invalid: {0}")]
14 InvalidBaseUrl(String),
15
16 /// The base URL contains a query string or fragment, which is not supported.
17 #[error("base URL must not contain a query string or fragment: {0}")]
18 InvalidBaseUrlShape(String),
19
20 /// The application name is empty.
21 #[error("application name cannot be empty")]
22 EmptyApplication,
23
24 /// No profiles were supplied.
25 #[error("at least one profile must be provided")]
26 EmptyProfiles,
27
28 /// The resource path is empty.
29 #[error("resource path cannot be empty")]
30 EmptyResourcePath,
31
32 /// A required environment variable is missing.
33 #[error("environment variable `{name}` is required")]
34 MissingEnvironmentVariable {
35 /// The environment variable name.
36 name: &'static str,
37 },
38
39 /// An environment variable has an invalid value.
40 #[error("environment variable `{name}` is invalid: {reason} (value: {value})")]
41 InvalidEnvironmentVariable {
42 /// The environment variable name.
43 name: &'static str,
44 /// A short reason.
45 reason: &'static str,
46 /// The provided value.
47 value: String,
48 },
49
50 /// The bootstrap configuration is internally inconsistent.
51 #[error("bootstrap configuration is invalid: {0}")]
52 InvalidBootstrapConfiguration(String),
53
54 /// A custom HTTP header name is invalid.
55 #[error("header name is invalid: {0}")]
56 InvalidHeaderName(String),
57
58 /// A custom HTTP header value is invalid.
59 #[error("header value is invalid for `{name}`: {value}")]
60 InvalidHeaderValue {
61 /// The header name.
62 name: String,
63 /// The header value.
64 value: String,
65 },
66
67 /// The HTTP request failed before a valid response was received.
68 #[error("request to {url} failed: {source}")]
69 Transport {
70 /// The target URL.
71 url: String,
72 /// The transport error.
73 #[source]
74 source: reqwest::Error,
75 },
76
77 /// The Config Server returned a non-success HTTP status.
78 #[error("config server returned {status} for {url}: {body}")]
79 HttpStatus {
80 /// The HTTP status code.
81 status: StatusCode,
82 /// The target URL.
83 url: String,
84 /// The response body, when available.
85 body: String,
86 },
87
88 /// The response body could not be parsed as JSON.
89 #[error("response from {url} is not valid JSON: {source}")]
90 Json {
91 /// The target URL.
92 url: String,
93 /// The parse error.
94 #[source]
95 source: serde_json::Error,
96 },
97
98 /// The response body could not be parsed as YAML.
99 #[error("response from {url} is not valid YAML: {source}")]
100 Yaml {
101 /// The target URL.
102 url: String,
103 /// The parse error.
104 #[source]
105 source: serde_yaml::Error,
106 },
107
108 /// The response body could not be parsed as TOML.
109 #[error("response from {url} is not valid TOML: {source}")]
110 Toml {
111 /// The target URL.
112 url: String,
113 /// The parse error.
114 #[source]
115 source: toml::de::Error,
116 },
117
118 /// The response body could not be parsed as Java properties.
119 #[error("response from {origin} is not valid Java properties: {reason}")]
120 Properties {
121 /// The origin being parsed.
122 origin: String,
123 /// A human-readable reason.
124 reason: String,
125 },
126
127 /// The response body was expected to be UTF-8 text but was not valid UTF-8.
128 #[error("response from {url} is not valid UTF-8: {source}")]
129 Utf8 {
130 /// The target URL.
131 url: String,
132 /// The UTF-8 decode error.
133 #[source]
134 source: FromUtf8Error,
135 },
136
137 /// Typed deserialization is not supported for the requested document kind.
138 #[error("typed deserialization is not supported for {format}")]
139 UnsupportedBindingFormat {
140 /// The format name.
141 format: &'static str,
142 },
143
144 /// The configuration payload could not be bound into the requested Rust type.
145 #[error("failed to bind configuration from {origin}: {source}")]
146 Bind {
147 /// A short description of the binding source.
148 origin: String,
149 /// The Serde error.
150 #[source]
151 source: serde_json::Error,
152 },
153}