Skip to main content

influxdb3_client/
error.rs

1use thiserror::Error;
2
3/// Describes a single rejected line in a partial write response.
4#[derive(Debug, Clone)]
5pub struct LineError {
6    /// 1-based line number in the submitted batch.
7    pub line: u64,
8    /// Error message from the server.
9    pub message: String,
10    /// The (possibly truncated) original line as echoed by the server.
11    pub original_line: Option<String>,
12}
13
14impl std::fmt::Display for LineError {
15    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16        write!(f, "line {}: {}", self.line, self.message)
17    }
18}
19
20/// Returned when `accept_partial=true` and the server rejected one or more lines.
21///
22/// The server accepts the valid lines and returns HTTP 400 with a JSON body
23/// listing every rejected line. Check `line_errors` for details.
24#[derive(Debug, Error)]
25#[error(
26    "partial write: {} line(s) rejected; first error: {}",
27    line_errors.len(),
28    line_errors.first().map(|e| e.message.as_str()).unwrap_or("unknown")
29)]
30pub struct PartialWriteError {
31    pub line_errors: Vec<LineError>,
32}
33
34/// Top-level error type for the InfluxDB 3 client.
35#[derive(Debug, Error)]
36pub enum Error {
37    /// HTTP transport error (connection refused, timeout, TLS, etc.)
38    #[error("HTTP error: {0}")]
39    Http(#[from] reqwest::Error),
40
41    /// Invalid URL (bad host format, etc.)
42    #[error("invalid URL: {0}")]
43    Url(#[from] url::ParseError),
44
45    /// JSON serialization / deserialization failure
46    #[error("JSON error: {0}")]
47    Json(#[from] serde_json::Error),
48
49    /// Arrow IPC or in-memory format error
50    #[error("Arrow error: {0}")]
51    Arrow(#[from] arrow::error::ArrowError),
52
53    /// gRPC status returned by Arrow Flight
54    #[error("Flight gRPC error: {0}")]
55    Flight(#[from] tonic::Status),
56
57    /// gRPC transport error (could not connect, TLS failure)
58    #[error("gRPC transport error: {0}")]
59    Transport(#[from] tonic::transport::Error),
60
61    /// Server returned an error response (non-2xx HTTP)
62    #[error("server error {code}: {message}")]
63    Server { code: u16, message: String },
64
65    /// An operation exceeded its configured timeout
66    #[error("operation timed out after {0:?}")]
67    Timeout(std::time::Duration),
68
69    /// Server accepted some lines and rejected others
70    #[error(transparent)]
71    PartialWrite(#[from] PartialWriteError),
72
73    /// Bad client configuration (missing required field, etc.)
74    #[error("configuration error: {0}")]
75    Config(String),
76
77    /// Required environment variable was not set
78    #[error("environment variable '{0}' is not set")]
79    EnvVar(String),
80}