Skip to main content

ErrorBuilder

Struct ErrorBuilder 

Source
pub struct ErrorBuilder { /* private fields */ }
Expand description

Builder for constructing errors with rich context

This builder enables fluent, ergonomic error construction with additional context.

§Examples

use oxigdal_core::error::OxiGdalError;
use std::path::Path;

let err = OxiGdalError::io_error_builder("Cannot read file")
    .with_path(Path::new("/data/file.tif"))
    .with_operation("read_raster")
    .with_suggestion("Check file permissions")
    .build();

Implementations§

Source§

impl ErrorBuilder

Source

pub fn new(error: OxiGdalError) -> Self

Create a new error builder

Source

pub fn with_path(self, path: impl AsRef<Path>) -> Self

Set the file path associated with this error

Source

pub fn with_operation(self, operation: impl Into<String>) -> Self

Set the operation name that failed

Source

pub fn with_parameter( self, key: impl Into<String>, value: impl Into<String>, ) -> Self

Add a parameter key-value pair

Source

pub fn with_suggestion(self, suggestion: impl Into<String>) -> Self

Set a custom suggestion (overrides the default suggestion)

Source

pub fn build(self) -> OxiGdalError

Build the final error, incorporating all context

Note: The additional context is stored and can be retrieved via the error’s context() method after building.

Source

pub fn into_error(self) -> OxiGdalError

Get the error without building (consumes self)

Source

pub fn error(&self) -> &OxiGdalError

Get a reference to the underlying error

Source

pub fn file_path(&self) -> Option<&Path>

Get the file path (if set)

Source

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

Get the operation name (if set)

Source

pub fn parameters(&self) -> &HashMap<String, String>

Get the parameters

Source

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

Get the custom suggestion (if set)

Source

pub fn suggestion(&self) -> Option<String>

Get the effective suggestion (custom or default)

Source

pub fn build_context(&self) -> ErrorContext

Build an enriched error context

Trait Implementations§

Source§

impl Debug for ErrorBuilder

Source§

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

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

impl From<ErrorBuilder> for OxiGdalError

Convert ErrorBuilder into OxiGdalError

Source§

fn from(builder: ErrorBuilder) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.