1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// ! Error types for asset workers.
//!
//! This module provides error handling functionality for asset workers. It defines
//! a custom error type that can wrap other errors and provide additional context.
//!
//! The module provides:
//!
//! - The [`AssetWorkerError`] struct which serves as a universal error type for all worker implementations
//! - Methods for creating errors with or without source errors
//! - Implementations of standard error traits
//!
//! # Error Handling Strategy
//!
//! The error handling strategy in this module follows these principles:
//!
//! 1. **Context Preservation**: Errors include both a human-readable message and the original error
//! 2. **Error Propagation**: The `From` trait implementation allows easy conversion from other error types
//! 3. **Diagnostic Information**: Errors provide clear and helpful diagnostic information
//!
//! When implementing worker types, use this error type to provide consistent error
//! handling throughout the asset worker system.
use Error;
use fmt;
/// 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(())
/// }
/// ```
///