From c50e38779da40084363232252c46d86dc59286d0 Mon Sep 17 00:00:00 2001 From: Aiden Park <275402320+vip892766gma@users.noreply.github.com> Date: Thu, 21 May 2026 17:18:52 +0000 Subject: [PATCH] chore: improve thiserror maintenance path --- tests/test_transparent.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/test_transparent.rs b/tests/test_transparent.rs index ee30f5b2..c458e6ba 100644 --- a/tests/test_transparent.rs +++ b/tests/test_transparent.rs @@ -63,6 +63,37 @@ fn test_transparent_enum_with_default_message() { assert_eq!("inner", error.source().unwrap().to_string()); } +#[test] +fn test_transparent_enum_generic() { + #[derive(Error, Debug)] + enum Error { + #[error("this failed")] + This, + #[error(transparent)] + Other(E), + } + + #[derive(Error, Debug)] + #[error("inner error")] + struct Inner; + + let error = Error::::This; + assert_eq!("this failed", error.to_string()); + + let error = Error::Other(Inner); + assert_eq!("inner error", error.to_string()); + assert!(error.source().is_none()); + + #[derive(Error, Debug)] + #[error("wrapped")] + struct WithSource(#[source] io::Error); + + let io = io::Error::new(io::ErrorKind::Other, "oh no!"); + let error = Error::Other(WithSource(io)); + assert_eq!("wrapped", error.to_string()); + assert_eq!("oh no!", error.source().unwrap().to_string()); +} + #[test] fn test_anyhow() { #[derive(Error, Debug)]