headwaters_client/error.rs
1//! Error type for the client.
2
3/// An error from constructing or calling the Headwaters read API.
4#[derive(Debug, thiserror::Error)]
5#[non_exhaustive]
6pub enum Error {
7 /// The configured base URL could not be parsed.
8 #[error("invalid base URL: {0}")]
9 InvalidBaseUrl(String),
10
11 /// A required environment variable was not set (see [`from_env`]).
12 ///
13 /// [`from_env`]: crate::HeadwatersClient::from_env
14 #[error("missing environment variable: {0}")]
15 MissingEnvVar(&'static str),
16
17 /// The RPC failed — a transport error, or a non-OK status from the server.
18 #[error("read API request failed: {0}")]
19 Rpc(#[from] connectrpc::ConnectError),
20
21 /// Constructing a cloud-provider credential client failed (e.g. invalid or
22 /// missing credentials). Only present with the `cloud-auth` feature.
23 #[cfg(feature = "cloud-auth")]
24 #[error("cloud auth setup failed: {0}")]
25 CloudAuth(#[from] olai_http::Error),
26}
27
28impl Error {
29 /// The Connect status code, when this is an [`Error::Rpc`] carrying one.
30 ///
31 /// Lets callers branch on the failure kind — e.g. distinguish a missing
32 /// entity ([`is_not_found`](Self::is_not_found)) from a transport failure.
33 pub fn code(&self) -> Option<connectrpc::ErrorCode> {
34 match self {
35 Error::Rpc(e) => Some(e.code),
36 _ => None,
37 }
38 }
39
40 /// True when the failure is a `not_found` status — the requested job,
41 /// dataset, or run does not exist.
42 pub fn is_not_found(&self) -> bool {
43 self.code() == Some(connectrpc::ErrorCode::NotFound)
44 }
45}