pub struct Error { /* private fields */ }Expand description
A failure with a message, optional HTTP diagnostics, and operation details.
Start with Self::message, Self::http_status, and Self::request_id.
Use Self::statement_details for a failed query, Self::append_details
for a rejected or uncertain append, and Self::write_details for a write
timeout. A timed-out write may already have committed; reconcile it before
replaying.
Self::is_retryable describes the failed operation. For a query that was
already submitted, resume its Self::statement_id through
crate::Client::statement_handle instead of submitting another query.
Implementations§
Source§impl Error
impl Error
Sourcepub fn new(kind: ErrorKind, message: impl Into<String>) -> Self
pub fn new(kind: ErrorKind, message: impl Into<String>) -> Self
Create a new Error with error kind and message.
Sourcepub fn with_context(self, key: &'static str, value: impl ToString) -> Self
pub fn with_context(self, key: &'static str, value: impl ToString) -> Self
Add more context in error.
Sourcepub fn set_source(self, src: impl Into<Error>) -> Self
pub fn set_source(self, src: impl Into<Error>) -> Self
Sourcepub fn write_details(&self) -> Option<&WriteErrorDetails>
pub fn write_details(&self) -> Option<&WriteErrorDetails>
Returns client timeout details for a table append after sending began. Existing error kinds, sources, and HTTP diagnostics remain available.
Sourcepub fn append_details(&self) -> Option<&AppendErrorDetails>
pub fn append_details(&self) -> Option<&AppendErrorDetails>
Return structured table-append failure details, when available.
Examples found in repository?
21async fn main() -> Result<(), Box<dyn std::error::Error>> {
22 let client = common::client()?;
23 let table = common::write_table(&client)?;
24
25 // Direct append sends exactly one caller-owned NDJSON request. Each value
26 // is serialized as one line; JSON arrays are not accepted by this API.
27 let ndjson = [
28 serde_json::json!({
29 "id": 1,
30 "occurred_at": jiff::Timestamp::now(),
31 "name": "first",
32 }),
33 serde_json::json!({
34 "id": 2,
35 "occurred_at": jiff::Timestamp::now(),
36 "name": "second",
37 }),
38 ]
39 .iter()
40 .map(serde_json::to_string)
41 .collect::<Result<Vec<_>, _>>()?
42 .join("\n");
43
44 match table.append(ndjson).await {
45 Ok(result) => {
46 println!("committed remotely: {} rows", result.num_rows_inserted);
47 Ok(())
48 }
49 Err(error) => {
50 if error.kind() == ErrorKind::AppendRowsFailed
51 && matches!(
52 error.append_details().map(|details| details.status),
53 Some(AppendState::Unknown)
54 )
55 {
56 eprintln!("commit outcome is unknown; reconcile before replaying this payload");
57 }
58 Err(error.into())
59 }
60 }
61}More examples
22async fn main() -> Result<(), Box<dyn std::error::Error>> {
23 let client = common::client()?;
24 let table = common::write_table(&client)?;
25
26 // The default Stop policy gives strict barriers. Local memory and request
27 // concurrency are bounded independently; concurrent batches have no
28 // defined commit order.
29 let stream = table
30 .append_stream()
31 .target_batch_bytes(32 * 1024)
32 .max_batch_rows(10_000)
33 .flush_interval(Duration::from_secs(1))
34 .max_buffered_bytes(1024 * 1024)
35 .max_concurrent_batches(4)
36 .attempt_timeout(Duration::from_secs(30))
37 .build()?;
38
39 let rows = (1..=10_000).map(|id| {
40 serde_json::json!({
41 "id": id,
42 "occurred_at": jiff::Timestamp::now(),
43 "name": format!("example-{id}"),
44 })
45 });
46
47 let admission_error = match stream.send_all(rows).await {
48 Ok(result) => {
49 println!("accepted locally: {} rows", result.accepted_rows);
50 None
51 }
52 Err(error) => {
53 // There is no stream-wide abort or rollback. Settle the already
54 // accepted prefix even if row production or admission stopped.
55 eprintln!("row admission stopped; settling the accepted prefix: {error}");
56 Some(error)
57 }
58 };
59
60 match stream.shutdown().await {
61 Ok(report) => {
62 println!("committed remotely: {} rows", report.committed_rows);
63 println!("final stream stats: {:?}", stream.stats());
64 }
65 Err(error) => {
66 if matches!(
67 error.append_details().map(|details| details.status),
68 Some(AppendState::Unknown)
69 ) {
70 eprintln!("commit outcome is unknown; reconcile before replaying");
71 } else {
72 eprintln!("bulk append failed: {error}");
73 }
74 eprintln!("final stream stats: {:?}", stream.stats());
75 return Err(error.into());
76 }
77 }
78
79 if let Some(error) = admission_error {
80 return Err(error.into());
81 }
82 Ok(())
83}Sourcepub fn statement_details(&self) -> Option<&StatementErrorDetails>
pub fn statement_details(&self) -> Option<&StatementErrorDetails>
Return structured statement failure details, when available.
Sourcepub fn statement_id(&self) -> Option<Uuid>
pub fn statement_id(&self) -> Option<Uuid>
Returns the statement identifier, when known. Use crate::Client::statement_handle
to inspect the existing execution instead of resubmitting it. An identifier
supplied before submission does not confirm that the server accepted it.
Sourcepub fn set_permanent(self) -> Self
pub fn set_permanent(self) -> Self
Set permanent status for error.
Sourcepub fn set_temporary(self) -> Self
pub fn set_temporary(self) -> Self
Set temporary status for error.
By set temporary, we indicate this error is retryable.
Sourcepub fn set_persistent(self) -> Self
pub fn set_persistent(self) -> Self
Set persistent status for error.
By setting persistent, we indicate the retry should be stopped.
Sourcepub fn kind(&self) -> ErrorKind
pub fn kind(&self) -> ErrorKind
Return the kind of this error.
Examples found in repository?
21async fn main() -> Result<(), Box<dyn std::error::Error>> {
22 let client = common::client()?;
23 let table = common::write_table(&client)?;
24
25 // Direct append sends exactly one caller-owned NDJSON request. Each value
26 // is serialized as one line; JSON arrays are not accepted by this API.
27 let ndjson = [
28 serde_json::json!({
29 "id": 1,
30 "occurred_at": jiff::Timestamp::now(),
31 "name": "first",
32 }),
33 serde_json::json!({
34 "id": 2,
35 "occurred_at": jiff::Timestamp::now(),
36 "name": "second",
37 }),
38 ]
39 .iter()
40 .map(serde_json::to_string)
41 .collect::<Result<Vec<_>, _>>()?
42 .join("\n");
43
44 match table.append(ndjson).await {
45 Ok(result) => {
46 println!("committed remotely: {} rows", result.num_rows_inserted);
47 Ok(())
48 }
49 Err(error) => {
50 if error.kind() == ErrorKind::AppendRowsFailed
51 && matches!(
52 error.append_details().map(|details| details.status),
53 Some(AppendState::Unknown)
54 )
55 {
56 eprintln!("commit outcome is unknown; reconcile before replaying this payload");
57 }
58 Err(error.into())
59 }
60 }
61}Sourcepub fn code(&self) -> Option<&str>
pub fn code(&self) -> Option<&str>
Returns the server error code, including codes introduced by newer servers.
Sourcepub fn details(&self) -> Option<&Value>
pub fn details(&self) -> Option<&Value>
Returns the original structured server details, when provided.
Sourcepub fn http_status(&self) -> Option<StatusCode>
pub fn http_status(&self) -> Option<StatusCode>
Return the HTTP response status when the error came from a server.
Sourcepub fn request_id(&self) -> Option<&str>
pub fn request_id(&self) -> Option<&str>
Return the request identifier supplied by ScopeDB or an intermediary.
Sourcepub fn retry_after(&self) -> Option<Duration>
pub fn retry_after(&self) -> Option<Duration>
Return the delay suggested by the HTTP Retry-After header.
Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
Return whether retrying this operation is currently appropriate.
For statement handles, retry on the same handle. Errors from query() or
execute() after submission never indicate that resubmitting is safe.
Sourcepub fn is_temporary(&self) -> bool
pub fn is_temporary(&self) -> bool
Check if this error is temporary.
Sourcepub fn is_permanent(&self) -> bool
pub fn is_permanent(&self) -> bool
Check if this error is permanent.
Sourcepub fn is_persistent(&self) -> bool
pub fn is_persistent(&self) -> bool
Check if this error is persistent.
Trait Implementations§
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()