pub struct ErrorData { /* private fields */ }Expand description
RAII wrapper for a duckdb_error_data handle.
Automatically destroyed when dropped. Carries a structured error category
(DuckDbErrorType) and a human-readable message.
Implements Display and std::error::Error, and
converts into ExtensionError via From (or
into_extension_error) so it can be
propagated with ?.
Implementations§
Source§impl ErrorData
impl ErrorData
Sourcepub fn new(error_type: DuckDbErrorType, message: &str) -> Self
pub fn new(error_type: DuckDbErrorType, message: &str) -> Self
Creates a new structured error with the given category and message.
An interior null byte in message is replaced by ?, the same as
every other error path in the crate, so no part of the message is lost.
Sourcepub const unsafe fn from_raw(raw: duckdb_error_data) -> Self
pub const unsafe fn from_raw(raw: duckdb_error_data) -> Self
Wraps a raw duckdb_error_data handle, taking ownership.
§Safety
raw must be a duckdb_error_data returned by a DuckDB API call (it may
be null). The caller must not destroy the handle after this call.
Sourcepub const fn as_raw(&self) -> duckdb_error_data
pub const fn as_raw(&self) -> duckdb_error_data
Returns the raw handle without consuming the ErrorData.
Sourcepub fn error_type(&self) -> DuckDbErrorType
pub fn error_type(&self) -> DuckDbErrorType
Returns the error category.
Sourcepub fn message(&self) -> Option<String>
pub fn message(&self) -> Option<String>
Returns the error message, or None if the handle is null or the message
is not valid UTF-8.
The returned string is owned by DuckDB and copied into a Rust String.
Sourcepub fn into_extension_error(self) -> ExtensionError
pub fn into_extension_error(self) -> ExtensionError
Consumes the ErrorData and converts it into an ExtensionError.
Useful for propagating a structured DuckDB error through ?.
Trait Implementations§
Source§impl Error for ErrorData
impl Error for ErrorData
1.30.0 · 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()
Source§impl From<ErrorData> for ExtensionError
impl From<ErrorData> for ExtensionError
Source§impl From<ExtensionError> for ErrorData
Wraps an ExtensionError’s message as DuckDbErrorType::Invalid
(“no specific category”: an ExtensionError carries none).
impl From<ExtensionError> for ErrorData
Wraps an ExtensionError’s message as DuckDbErrorType::Invalid
(“no specific category”: an ExtensionError carries none).
This is what lets ? propagate a Value or
builder error inside an Appender::row
closure, whose error type is ErrorData under duckdb-1-5:
use quack_rs::appender::Appender;
use quack_rs::value::Value;
appender.row(|row| {
let price = Value::decimal(9, 2, 1999)?; // `ExtensionError` -> `ErrorData`
row.append_value(&price)
})