pub struct ExtensionError { /* private fields */ }Expand description
An error that can occur during DuckDB extension initialization or registration.
This type is designed for use with the ? operator inside the extension
entry point. It can be reported back to DuckDB via access.set_error.
§Construction
use quack_rs::error::ExtensionError;
// From a string literal
let e = ExtensionError::from("something went wrong");
// From a String
let msg = format!("failed: {}", 42);
let e = ExtensionError::from(msg);
// Wrapping another error
let parse_err: Result<i32, _> = "not a number".parse();
let e = parse_err.map_err(ExtensionError::from_error);Implementations§
Source§impl ExtensionError
impl ExtensionError
Sourcepub fn new(message: impl Into<String>) -> Self
pub fn new(message: impl Into<String>) -> Self
Creates a new ExtensionError with the given message.
§Example
use quack_rs::error::ExtensionError;
let err = ExtensionError::new("registration failed");
assert_eq!(err.to_string(), "registration failed");Sourcepub fn from_error<E: Error>(e: E) -> Self
pub fn from_error<E: Error>(e: E) -> Self
Wraps any std::error::Error into an ExtensionError.
§Example
use quack_rs::error::ExtensionError;
let result: Result<i32, _> = "abc".parse::<i32>();
let err = result.map_err(ExtensionError::from_error);
assert!(err.is_err());Sourcepub fn to_c_string(&self) -> CString
pub fn to_c_string(&self) -> CString
Converts this error into a CString suitable for passing to set_error.
A null byte in the message (valid in a Rust String, not in a C
string) is replaced by ?, as on every error path in this crate
(message_to_c_string), so the
text after it is not lost.
§Example
use quack_rs::error::ExtensionError;
let err = ExtensionError::new("oops");
assert_eq!(err.to_c_string().to_str().unwrap(), "oops");
let err = ExtensionError::new("a\0b");
assert_eq!(err.to_c_string().to_str().unwrap(), "a?b");Trait Implementations§
Source§impl Clone for ExtensionError
impl Clone for ExtensionError
Source§impl Debug for ExtensionError
impl Debug for ExtensionError
Source§impl Display for ExtensionError
impl Display for ExtensionError
impl Eq for ExtensionError
Source§impl Error for ExtensionError
impl Error for ExtensionError
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<&str> for ExtensionError
impl From<&str> for ExtensionError
Source§impl From<Error> for ExtensionError
impl From<Error> for ExtensionError
Source§impl From<Error> for ExtensionError
impl From<Error> for ExtensionError
Source§impl From<ErrorData> for ExtensionError
Available on crate feature duckdb-1-5 only.
impl From<ErrorData> for ExtensionError
duckdb-1-5 only.Source§impl From<ExtensionError> for ErrorData
Available on crate feature duckdb-1-5 only.Wraps an ExtensionError’s message as DuckDbErrorType::Invalid
(“no specific category”: an ExtensionError carries none).
impl From<ExtensionError> for ErrorData
duckdb-1-5 only.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)
})