Skip to main content

Error

Struct Error 

Source
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

Source

pub fn new(kind: ErrorKind, message: impl Into<String>) -> Self

Create a new Error with error kind and message.

Source

pub fn with_context(self, key: &'static str, value: impl ToString) -> Self

Add more context in error.

Source

pub fn set_source(self, src: impl Into<Error>) -> Self

Set source for error.

§Notes

If the source has been set, we will raise a panic here.

Source

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.

Source

pub fn append_details(&self) -> Option<&AppendErrorDetails>

Return structured table-append failure details, when available.

Examples found in repository?
examples/append.rs (line 52)
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
Hide additional examples
examples/bulk_append.rs (line 67)
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}
Source

pub fn statement_details(&self) -> Option<&StatementErrorDetails>

Return structured statement failure details, when available.

Source

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.

Source

pub fn set_permanent(self) -> Self

Set permanent status for error.

Source

pub fn set_temporary(self) -> Self

Set temporary status for error.

By set temporary, we indicate this error is retryable.

Source

pub fn set_persistent(self) -> Self

Set persistent status for error.

By setting persistent, we indicate the retry should be stopped.

Source

pub fn kind(&self) -> ErrorKind

Return the kind of this error.

Examples found in repository?
examples/append.rs (line 50)
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}
Source

pub fn code(&self) -> Option<&str>

Returns the server error code, including codes introduced by newer servers.

Source

pub fn details(&self) -> Option<&Value>

Returns the original structured server details, when provided.

Source

pub fn message(&self) -> &str

Return the error message.

Source

pub fn http_status(&self) -> Option<StatusCode>

Return the HTTP response status when the error came from a server.

Source

pub fn request_id(&self) -> Option<&str>

Return the request identifier supplied by ScopeDB or an intermediary.

Source

pub fn retry_after(&self) -> Option<Duration>

Return the delay suggested by the HTTP Retry-After header.

Source

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.

Source

pub fn is_temporary(&self) -> bool

Check if this error is temporary.

Source

pub fn is_permanent(&self) -> bool

Check if this error is permanent.

Source

pub fn is_persistent(&self) -> bool

Check if this error is persistent.

Trait Implementations§

Source§

impl Clone for Error

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for Error

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more

Auto Trait Implementations§

§

impl Freeze for Error

§

impl RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

§

impl UnwindSafe for Error

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more