pub struct AssetWorkerError {
pub msg: String,
pub source: Option<Box<dyn Error + Send + Sync>>,
}Expand description
A custom error type for asset workers that wraps another error with an optional message.
AssetWorkerError provides a consistent error type for all asset worker implementations,
allowing errors to be propagated with context. It can be used either as a standalone error
with just a message, or it can wrap another error while adding additional context.
§Examples
Creating a standalone error:
use bothan_lib::worker::error::AssetWorkerError;
let error = AssetWorkerError::new("Failed to initialize worker");Creating an error that wraps another error:
use bothan_lib::worker::error::AssetWorkerError;
use std::io;
let io_error = io::Error::new(io::ErrorKind::NotFound, "Resource not found");
let error = AssetWorkerError::with_source("Failed to fetch asset data", io_error);Using the From trait for automatic conversion with the ? operator for any error type that implements the Error trait:
use bothan_lib::worker::error::AssetWorkerError;
use std::io;
fn process() -> Result<(), AssetWorkerError> {
// The ? operator automatically converts io::Error to AssetWorkerError using From
let result = std::fs::read_to_string("config.json")?;
// Process the result...
Ok(())
}Fields§
§msg: StringA human-readable error message.
source: Option<Box<dyn Error + Send + Sync>>The optional source error that caused this error.
Implementations§
Source§impl AssetWorkerError
impl AssetWorkerError
Sourcepub fn new(msg: impl Into<String>) -> Self
pub fn new(msg: impl Into<String>) -> Self
Create a new AssetWorkerError with a message.
This method creates a standalone error without a source error. Use this when the error originates within the worker code.
§Examples
use bothan_lib::worker::error::AssetWorkerError;
let error = AssetWorkerError::new("Failed to initialize worker");Sourcepub fn with_source<E>(msg: impl Into<String>, source: E) -> Self
pub fn with_source<E>(msg: impl Into<String>, source: E) -> Self
Create a new AssetWorkerError with a message and a source error.
This method creates an error that wraps another error, adding context about the operation that was being performed when the error occurred.
§Examples
use bothan_lib::worker::error::AssetWorkerError;
use std::io;
let io_error = io::Error::new(io::ErrorKind::NotFound, "Resource not found");
let error = AssetWorkerError::with_source("Failed to fetch asset data", io_error);Trait Implementations§
Source§impl Debug for AssetWorkerError
impl Debug for AssetWorkerError
Source§impl Display for AssetWorkerError
impl Display for AssetWorkerError
Auto Trait Implementations§
impl Freeze for AssetWorkerError
impl !RefUnwindSafe for AssetWorkerError
impl Send for AssetWorkerError
impl Sync for AssetWorkerError
impl Unpin for AssetWorkerError
impl !UnwindSafe for AssetWorkerError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request