Skip to main content

strands/
error.rs

1//! The SDK's error types.
2//!
3//! Each error is a struct with its own message text. [`Error`] wraps them, one variant per type, so
4//! callers can branch with `match` and still reach the type's fields.
5
6use std::error::Error as StdError;
7use std::sync::Arc;
8
9use crate::interrupt::InterruptError;
10use crate::types::Message;
11
12/// A boxed, thread-safe error used as the `source` of wrapping errors.
13pub type BoxError = Box<dyn StdError + Send + Sync + 'static>;
14
15/// `Result` with [`Error`] as the default error type.
16pub type Result<T, E = Error> = std::result::Result<T, E>;
17
18/// Every error the SDK returns.
19///
20/// Display and [`source`](StdError::source) delegate to the wrapped error, so its message and cause
21/// chain are preserved.
22#[derive(Debug, thiserror::Error)]
23#[non_exhaustive]
24pub enum Error {
25    /// A model provider failed (`ModelError`).
26    #[error(transparent)]
27    Model(#[from] ModelError),
28    /// The input exceeded the model's context window (`ContextWindowOverflowError`).
29    #[error(transparent)]
30    ContextWindowOverflow(#[from] ContextWindowOverflowError),
31    /// The model stopped at its output token limit (`MaxTokensError`).
32    #[error(transparent)]
33    MaxTokens(#[from] MaxTokensError),
34    /// The provider throttled the request (`ModelThrottledError`).
35    #[error(transparent)]
36    ModelThrottled(#[from] ModelThrottledError),
37    /// The network connection to the provider failed (`ModelNetworkError`).
38    #[error(transparent)]
39    ModelNetwork(#[from] ModelNetworkError),
40    /// A value could not be serialized to JSON (`JsonValidationError`).
41    #[error(transparent)]
42    JsonValidation(#[from] JsonValidationError),
43    /// A tool failed validation during registration (`ToolValidationError`).
44    #[error(transparent)]
45    ToolValidation(#[from] ToolValidationError),
46    /// No tool is registered under the requested name (`ToolNotFoundError`).
47    #[error(transparent)]
48    ToolNotFound(#[from] ToolNotFoundError),
49    /// The model did not produce structured output (`StructuredOutputError`).
50    #[error(transparent)]
51    StructuredOutput(#[from] StructuredOutputError),
52    /// A default was read before one was configured (`DefaultNotConfiguredError`).
53    #[error(transparent)]
54    DefaultNotConfigured(#[from] DefaultNotConfiguredError),
55    /// A storage operation failed (`StorageError`).
56    #[error(transparent)]
57    Storage(#[from] StorageError),
58    /// A session operation failed (`SessionError`).
59    #[error(transparent)]
60    Session(#[from] SessionError),
61    /// Sandbox execution timed out (`SandboxTimeoutError`).
62    #[error(transparent)]
63    SandboxTimeout(#[from] SandboxTimeoutError),
64    /// Sandbox execution was aborted (`SandboxAbortError`).
65    #[error(transparent)]
66    SandboxAbort(#[from] SandboxAbortError),
67    /// A sandbox path does not exist (`SandboxPathNotFoundError`).
68    #[error(transparent)]
69    SandboxPathNotFound(#[from] SandboxPathNotFoundError),
70    /// A sandbox path is a directory (`SandboxIsADirectoryError`).
71    #[error(transparent)]
72    SandboxIsADirectory(#[from] SandboxIsADirectoryError),
73    /// A sandbox path is not accessible (`SandboxPermissionError`).
74    #[error(transparent)]
75    SandboxPermission(#[from] SandboxPermissionError),
76    /// An MCP client failed (`ProtocolError`, `SdkError` or a plain MCP client error).
77    #[cfg(feature = "mcp")]
78    #[error(transparent)]
79    Mcp(crate::mcp::McpError),
80    /// A hook raised interrupts outside the events that stop for them (`InterruptError`).
81    #[error(transparent)]
82    Interrupt(#[from] InterruptError),
83    /// Any other failure, such as I/O or JSON decoding.
84    #[error(transparent)]
85    Other(BoxError),
86}
87
88impl Error {
89    /// Wraps any error as [`Error::Other`].
90    pub fn other(error: impl Into<BoxError>) -> Self {
91        Self::Other(error.into())
92    }
93
94    /// Recovers the typed error behind a boxed one: a boxed [`Error`] is unwrapped and an
95    /// [`InterruptError`] becomes [`Error::Interrupt`]; anything else is [`Error::Other`].
96    #[must_use]
97    pub fn from_boxed(error: BoxError) -> Self {
98        let error = match error.downcast::<Self>() {
99            Ok(error) => return *error,
100            Err(error) => error,
101        };
102        match error.downcast::<InterruptError>() {
103            Ok(interrupts) => Self::Interrupt(*interrupts),
104            Err(error) => Self::Other(error),
105        }
106    }
107
108    /// The wrapped error's type name, for example `"ContextWindowOverflowError"`.
109    ///
110    /// [`Error::Other`] reports `"Error"`.
111    #[must_use]
112    pub fn name(&self) -> &'static str {
113        match self {
114            Self::Model(_) => ModelError::NAME,
115            Self::ContextWindowOverflow(_) => ContextWindowOverflowError::NAME,
116            Self::MaxTokens(_) => MaxTokensError::NAME,
117            Self::ModelThrottled(_) => ModelThrottledError::NAME,
118            Self::ModelNetwork(_) => ModelNetworkError::NAME,
119            Self::JsonValidation(_) => JsonValidationError::NAME,
120            Self::ToolValidation(_) => ToolValidationError::NAME,
121            Self::ToolNotFound(_) => ToolNotFoundError::NAME,
122            Self::StructuredOutput(_) => StructuredOutputError::NAME,
123            Self::DefaultNotConfigured(_) => DefaultNotConfiguredError::NAME,
124            Self::Storage(_) => StorageError::NAME,
125            Self::Session(_) => SessionError::NAME,
126            Self::SandboxTimeout(_) => SandboxTimeoutError::NAME,
127            Self::SandboxAbort(_) => SandboxAbortError::NAME,
128            Self::SandboxPathNotFound(_) => SandboxPathNotFoundError::NAME,
129            Self::SandboxIsADirectory(_) => SandboxIsADirectoryError::NAME,
130            Self::SandboxPermission(_) => SandboxPermissionError::NAME,
131            #[cfg(feature = "mcp")]
132            Self::Mcp(error) => error.name(),
133            Self::Interrupt(_) => "InterruptError",
134            Self::Other(_) => "Error",
135        }
136    }
137
138    /// Whether this is a model error: `ModelError` or one of the more specific model errors.
139    #[must_use]
140    pub fn is_model_error(&self) -> bool {
141        matches!(
142            self,
143            Self::Model(_)
144                | Self::ContextWindowOverflow(_)
145                | Self::MaxTokens(_)
146                | Self::ModelThrottled(_)
147                | Self::ModelNetwork(_)
148        )
149    }
150}
151
152impl From<serde_json::Error> for Error {
153    fn from(error: serde_json::Error) -> Self {
154        Self::Other(Box::new(error))
155    }
156}
157
158impl From<std::io::Error> for Error {
159    fn from(error: std::io::Error) -> Self {
160        Self::Other(Box::new(error))
161    }
162}
163
164macro_rules! message_error {
165    ($(#[$doc:meta])* $name:ident) => {
166        $(#[$doc])*
167        #[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
168        #[error("{message}")]
169        #[non_exhaustive]
170        pub struct $name {
171            /// The error message.
172            pub message: String,
173        }
174
175        impl $name {
176            /// The type name [`Error::name`] reports.
177            pub const NAME: &'static str = stringify!($name);
178
179            /// Creates the error with a message.
180            pub fn new(message: impl Into<String>) -> Self {
181                Self { message: message.into() }
182            }
183        }
184    };
185}
186
187macro_rules! source_error {
188    ($(#[$doc:meta])* $name:ident) => {
189        $(#[$doc])*
190        #[derive(Debug, thiserror::Error)]
191        #[error("{message}")]
192        #[non_exhaustive]
193        pub struct $name {
194            /// The error message.
195            pub message: String,
196            /// The underlying cause.
197            #[source]
198            pub source: Option<BoxError>,
199        }
200
201        impl $name {
202            /// The type name [`Error::name`] reports.
203            pub const NAME: &'static str = stringify!($name);
204
205            /// Creates the error with a message and no cause.
206            pub fn new(message: impl Into<String>) -> Self {
207                Self { message: message.into(), source: None }
208            }
209
210            /// Sets the underlying cause.
211            #[must_use]
212            pub fn with_source(mut self, source: impl Into<BoxError>) -> Self {
213                self.source = Some(source.into());
214                self
215            }
216        }
217    };
218}
219
220source_error!(
221    /// A model provider failed (`ModelError`), the base of the model error family.
222    ModelError
223);
224
225/// The combined input exceeded the model's context window (`ContextWindowOverflowError`).
226///
227/// The cause is shared rather than owned so the error stays `Clone`: conversation managers
228/// receive a copy of the error that triggered the reduction.
229#[derive(Debug, Clone, thiserror::Error)]
230#[error("{message}")]
231#[non_exhaustive]
232pub struct ContextWindowOverflowError {
233    /// The error message.
234    pub message: String,
235    /// The underlying cause.
236    #[source]
237    pub source: Option<Arc<dyn StdError + Send + Sync + 'static>>,
238}
239
240impl ContextWindowOverflowError {
241    /// The type name [`Error::name`] reports.
242    pub const NAME: &'static str = "ContextWindowOverflowError";
243
244    /// Creates the error with a message and no cause.
245    pub fn new(message: impl Into<String>) -> Self {
246        Self {
247            message: message.into(),
248            source: None,
249        }
250    }
251
252    /// Sets the underlying cause.
253    #[must_use]
254    pub fn with_source(mut self, source: impl Into<BoxError>) -> Self {
255        self.source = Some(Arc::from(source.into()));
256        self
257    }
258}
259
260/// The model stopped because it reached its output token limit (`MaxTokensError`).
261///
262/// Carries the partial assistant message generated before the limit.
263#[derive(Debug, Clone, PartialEq, thiserror::Error)]
264#[error("{message}")]
265#[non_exhaustive]
266pub struct MaxTokensError {
267    /// The error message.
268    pub message: String,
269    /// The partial assistant message generated before the token limit.
270    pub partial_message: Box<Message>,
271}
272
273impl MaxTokensError {
274    /// The type name [`Error::name`] reports.
275    pub const NAME: &'static str = "MaxTokensError";
276
277    /// Creates the error with a message and the partial message.
278    pub fn new(message: impl Into<String>, partial_message: Message) -> Self {
279        Self {
280            message: message.into(),
281            partial_message: Box::new(partial_message),
282        }
283    }
284}
285
286source_error!(
287    /// The provider throttled or rate limited the request (`ModelThrottledError`).
288    ModelThrottledError
289);
290
291source_error!(
292    /// The network connection to the model provider failed (`ModelNetworkError`).
293    ///
294    /// Retrying the same request may succeed.
295    ModelNetworkError
296);
297
298message_error!(
299    /// A value contains data that cannot be serialized to JSON (`JsonValidationError`).
300    JsonValidationError
301);
302
303message_error!(
304    /// A tool failed validation during registration (`ToolValidationError`).
305    ToolValidationError
306);
307
308/// No registered tool matches the requested name (`ToolNotFoundError`).
309#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
310#[error("Tool '{tool_name}' not found")]
311#[non_exhaustive]
312pub struct ToolNotFoundError {
313    /// The tool name that was requested but not found.
314    pub tool_name: String,
315}
316
317impl ToolNotFoundError {
318    /// The type name [`Error::name`] reports.
319    pub const NAME: &'static str = "ToolNotFoundError";
320
321    /// Creates the error for a tool name.
322    pub fn new(tool_name: impl Into<String>) -> Self {
323        Self {
324            tool_name: tool_name.into(),
325        }
326    }
327}
328
329message_error!(
330    /// The model failed to produce structured output (`StructuredOutputError`).
331    StructuredOutputError
332);
333
334message_error!(
335    /// A default value was read before one was configured (`DefaultNotConfiguredError`).
336    DefaultNotConfiguredError
337);
338
339source_error!(
340    /// A storage operation failed (`StorageError`), whatever the backend.
341    StorageError
342);
343
344source_error!(
345    /// A session operation failed (`SessionError`), such as reading or restoring session data.
346    SessionError
347);
348
349/// Sandbox execution exceeded its timeout (`SandboxTimeoutError`).
350///
351/// `stdout` and `stderr` hold what the process wrote before it was killed.
352#[derive(Debug, Clone, PartialEq, thiserror::Error)]
353#[error("Execution timed out after {seconds} seconds")]
354#[non_exhaustive]
355pub struct SandboxTimeoutError {
356    /// The timeout that elapsed, in seconds.
357    pub seconds: f64,
358    /// Output written before the timeout.
359    pub stdout: String,
360    /// Error output written before the timeout.
361    pub stderr: String,
362}
363
364impl SandboxTimeoutError {
365    /// The type name [`Error::name`] reports.
366    pub const NAME: &'static str = "SandboxTimeoutError";
367
368    /// Creates the error for a timeout in seconds, with empty output.
369    pub fn new(seconds: f64) -> Self {
370        Self {
371            seconds,
372            stdout: String::new(),
373            stderr: String::new(),
374        }
375    }
376
377    /// Sets the output captured before the timeout.
378    #[must_use]
379    pub fn with_output(mut self, stdout: impl Into<String>, stderr: impl Into<String>) -> Self {
380        self.stdout = stdout.into();
381        self.stderr = stderr.into();
382        self
383    }
384}
385
386/// Sandbox execution was aborted through its cancel signal (`SandboxAbortError`).
387///
388/// `stdout` and `stderr` hold what the process wrote before it was killed.
389#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
390#[error("{message}")]
391#[non_exhaustive]
392pub struct SandboxAbortError {
393    /// Output written before the abort.
394    pub stdout: String,
395    /// Error output written before the abort.
396    pub stderr: String,
397    message: String,
398}
399
400impl SandboxAbortError {
401    /// The type name [`Error::name`] reports.
402    pub const NAME: &'static str = "SandboxAbortError";
403
404    /// Creates the error, with empty output.
405    pub fn new() -> Self {
406        Self {
407            stdout: String::new(),
408            stderr: String::new(),
409            message: "Execution aborted".to_owned(),
410        }
411    }
412
413    /// Sets the output captured before the abort.
414    #[must_use]
415    pub fn with_output(mut self, stdout: impl Into<String>, stderr: impl Into<String>) -> Self {
416        self.stdout = stdout.into();
417        self.stderr = stderr.into();
418        self
419    }
420
421    /// Appends `detail` to the message on its own line; a tool's caller sees only the message.
422    #[must_use]
423    pub(crate) fn with_detail(mut self, detail: &str) -> Self {
424        self.message = format!("{}\n{detail}", self.message);
425        self
426    }
427}
428
429impl Default for SandboxAbortError {
430    fn default() -> Self {
431        Self::new()
432    }
433}
434
435macro_rules! sandbox_path_error {
436    ($(#[$doc:meta])* $name:ident, $prefix:literal, $code:literal) => {
437        $(#[$doc])*
438        #[derive(Debug, thiserror::Error)]
439        #[error("{}: {path}", $prefix)]
440        #[non_exhaustive]
441        pub struct $name {
442            /// The path the operation failed on.
443            pub path: String,
444            /// The underlying cause.
445            #[source]
446            pub source: Option<BoxError>,
447        }
448
449        impl $name {
450            /// The type name [`Error::name`] reports.
451            pub const NAME: &'static str = stringify!($name);
452
453            /// The POSIX errno name this error matches.
454            pub const CODE: &'static str = $code;
455
456            /// Creates the error for a path.
457            pub fn new(path: impl Into<String>) -> Self {
458                Self { path: path.into(), source: None }
459            }
460
461            /// Sets the underlying cause.
462            #[must_use]
463            pub fn with_source(mut self, source: impl Into<BoxError>) -> Self {
464                self.source = Some(source.into());
465                self
466            }
467
468            /// The POSIX errno name this error matches.
469            #[must_use]
470            pub fn code(&self) -> &'static str {
471                Self::CODE
472            }
473        }
474    };
475}
476
477sandbox_path_error!(
478    /// A sandbox path does not exist (`SandboxPathNotFoundError`, code `ENOENT`).
479    SandboxPathNotFoundError,
480    "Path not found",
481    "ENOENT"
482);
483
484sandbox_path_error!(
485    /// A sandbox path is a directory where a file was expected (`SandboxIsADirectoryError`, code `EISDIR`).
486    SandboxIsADirectoryError,
487    "Is a directory",
488    "EISDIR"
489);
490
491sandbox_path_error!(
492    /// A sandbox file, or a directory above it, is not accessible (`SandboxPermissionError`, code `EACCES`).
493    SandboxPermissionError,
494    "Permission denied",
495    "EACCES"
496);
497
498#[cfg(test)]
499mod tests {
500    use super::*;
501    use crate::types::{Message, Role, TextBlock};
502
503    fn partial_message() -> Message {
504        Message::new(Role::Assistant, vec![TextBlock::new("partial response").into()])
505    }
506
507    #[test]
508    fn model_error_creates_an_error_with_the_correct_message() {
509        let error = ModelError::new("Model error occurred");
510        assert_eq!(error.to_string(), "Model error occurred");
511    }
512
513    #[test]
514    fn model_error_has_the_correct_error_name() {
515        assert_eq!(Error::from(ModelError::new("test")).name(), "ModelError");
516    }
517
518    #[test]
519    fn model_error_is_an_instance_of_error() {
520        let error: &dyn StdError = &ModelError::new("test");
521        assert_eq!(error.to_string(), "test");
522    }
523
524    #[test]
525    fn model_error_stores_the_cause_error() {
526        let error = ModelError::new("wrapped error").with_source(std::io::Error::other("original error"));
527        assert_eq!(error.to_string(), "wrapped error");
528        assert_eq!(
529            error.source().map(ToString::to_string).as_deref(),
530            Some("original error")
531        );
532    }
533
534    #[test]
535    fn context_window_overflow_error_preserves_the_original_failure() {
536        let error = ContextWindowOverflowError::new("context overflow")
537            .with_source(std::io::Error::other("provider context limit"));
538        let source = StdError::source(&error).expect("a cause");
539        assert_eq!(source.to_string(), "provider context limit");
540        assert!(Error::from(error).is_model_error());
541    }
542
543    #[test]
544    fn context_window_overflow_error_creates_an_error_with_the_correct_message() {
545        let error = ContextWindowOverflowError::new("Context window overflow occurred");
546        assert_eq!(error.to_string(), "Context window overflow occurred");
547    }
548
549    #[test]
550    fn context_window_overflow_error_has_the_correct_error_name() {
551        let error = Error::from(ContextWindowOverflowError::new("test"));
552        assert_eq!(error.name(), "ContextWindowOverflowError");
553    }
554
555    #[test]
556    fn context_window_overflow_error_is_an_instance_of_model_error() {
557        assert!(Error::from(ContextWindowOverflowError::new("test")).is_model_error());
558    }
559
560    #[test]
561    fn max_tokens_error_creates_an_error_with_the_correct_message() {
562        let error = MaxTokensError::new("Max tokens reached", partial_message());
563        assert_eq!(error.to_string(), "Max tokens reached");
564    }
565
566    #[test]
567    fn max_tokens_error_has_the_correct_error_name() {
568        let error = Error::from(MaxTokensError::new("test", partial_message()));
569        assert_eq!(error.name(), "MaxTokensError");
570    }
571
572    #[test]
573    fn max_tokens_error_stores_the_partial_message() {
574        let partial = partial_message();
575        let error = MaxTokensError::new("Max tokens reached", partial.clone());
576        assert_eq!(*error.partial_message, partial);
577    }
578
579    #[test]
580    fn max_tokens_error_is_an_instance_of_model_error() {
581        assert!(Error::from(MaxTokensError::new("test", partial_message())).is_model_error());
582    }
583
584    #[test]
585    fn model_throttled_error_creates_an_error_with_the_correct_message() {
586        assert_eq!(
587            ModelThrottledError::new("Rate limit exceeded").to_string(),
588            "Rate limit exceeded"
589        );
590    }
591
592    #[test]
593    fn model_throttled_error_has_the_correct_error_name() {
594        assert_eq!(
595            Error::from(ModelThrottledError::new("test")).name(),
596            "ModelThrottledError"
597        );
598    }
599
600    #[test]
601    fn model_throttled_error_is_an_instance_of_model_error() {
602        assert!(Error::from(ModelThrottledError::new("test")).is_model_error());
603    }
604
605    #[test]
606    fn preserves_the_original_error_as_cause() {
607        let error = Error::from(
608            ModelThrottledError::new("Rate limit exceeded")
609                .with_source(std::io::Error::other("Original rate limit error")),
610        );
611        assert_eq!(
612            error.source().map(ToString::to_string).as_deref(),
613            Some("Original rate limit error")
614        );
615    }
616
617    #[test]
618    fn has_undefined_cause_when_not_provided() {
619        assert!(ModelThrottledError::new("Rate limit exceeded").source().is_none());
620    }
621
622    #[test]
623    fn is_a_model_error_with_its_own_name_that_preserves_the_cause() {
624        let error = Error::from(
625            ModelNetworkError::new("Language model stream error: Failed to fetch")
626                .with_source(std::io::Error::other("Failed to fetch")),
627        );
628        assert!(error.is_model_error());
629        assert_eq!(error.name(), "ModelNetworkError");
630        assert_eq!(error.to_string(), "Language model stream error: Failed to fetch");
631        assert_eq!(
632            error.source().map(ToString::to_string).as_deref(),
633            Some("Failed to fetch")
634        );
635    }
636
637    #[test]
638    fn non_model_errors_are_not_model_errors() {
639        assert!(!Error::from(ToolValidationError::new("bad")).is_model_error());
640        assert!(!Error::other(std::io::Error::other("io")).is_model_error());
641    }
642
643    #[test]
644    fn tool_not_found_error_message_and_name() {
645        let error = Error::from(ToolNotFoundError::new("calculator"));
646        assert_eq!(error.to_string(), "Tool 'calculator' not found");
647        assert_eq!(error.name(), "ToolNotFoundError");
648    }
649
650    #[test]
651    fn message_classes_keep_their_message_and_name() {
652        let cases = [
653            (Error::from(JsonValidationError::new("a")), "JsonValidationError"),
654            (Error::from(ToolValidationError::new("b")), "ToolValidationError"),
655            (Error::from(StructuredOutputError::new("c")), "StructuredOutputError"),
656            (
657                Error::from(DefaultNotConfiguredError::new("d")),
658                "DefaultNotConfiguredError",
659            ),
660            (Error::from(StorageError::new("e")), "StorageError"),
661            (Error::from(SessionError::new("f")), "SessionError"),
662        ];
663        for ((error, name), message) in cases.iter().zip(["a", "b", "c", "d", "e", "f"]) {
664            assert_eq!(error.name(), *name);
665            assert_eq!(error.to_string(), message);
666        }
667    }
668
669    #[test]
670    fn storage_error_keeps_its_cause_through_error() {
671        let error = Error::from(StorageError::new("Failed to write").with_source(std::io::Error::other("disk full")));
672        assert_eq!(error.source().map(ToString::to_string).as_deref(), Some("disk full"));
673    }
674
675    #[test]
676    fn sandbox_errors_use_the_ts_messages_and_codes() {
677        assert_eq!(
678            SandboxTimeoutError::new(5.0).to_string(),
679            "Execution timed out after 5 seconds"
680        );
681        assert_eq!(
682            SandboxTimeoutError::new(0.5).to_string(),
683            "Execution timed out after 0.5 seconds"
684        );
685        assert_eq!(SandboxAbortError::new().to_string(), "Execution aborted");
686        let not_found = SandboxPathNotFoundError::new("/tmp/missing");
687        assert_eq!(not_found.to_string(), "Path not found: /tmp/missing");
688        assert_eq!(not_found.code(), "ENOENT");
689        let directory = SandboxIsADirectoryError::new("/tmp");
690        assert_eq!(directory.to_string(), "Is a directory: /tmp");
691        assert_eq!(directory.code(), "EISDIR");
692        let permission = SandboxPermissionError::new("/root/secret");
693        assert_eq!(permission.to_string(), "Permission denied: /root/secret");
694        assert_eq!(permission.code(), "EACCES");
695        assert_eq!(Error::from(permission).name(), "SandboxPermissionError");
696    }
697
698    #[test]
699    fn sandbox_timeout_keeps_partial_output() {
700        let error = SandboxTimeoutError::new(1.0).with_output("out", "err");
701        assert_eq!((error.stdout.as_str(), error.stderr.as_str()), ("out", "err"));
702    }
703
704    #[test]
705    fn other_wraps_any_error_with_its_source_message() {
706        let error = Error::from(serde_json::from_str::<serde_json::Value>("{").unwrap_err());
707        assert_eq!(error.name(), "Error");
708        assert!(error.to_string().contains("EOF"));
709    }
710}