diff --git a/src/providers/anthropic.rs b/src/providers/anthropic.rs index 249e0e6..cf3778f 100644 --- a/src/providers/anthropic.rs +++ b/src/providers/anthropic.rs @@ -614,15 +614,20 @@ mod tests { assert_eq!(chain, "single error"); } + /// 用 thiserror 构造真正的嵌套 source 链,验证 "caused by" 拼接 + #[derive(Debug, thiserror::Error)] + enum OuterError { + #[error("outer wrapper")] + Wrapped(#[source] std::io::Error), + } + #[test] fn test_format_error_chain_nested() { let inner = std::io::Error::new(std::io::ErrorKind::Other, "root cause"); - let outer = std::io::Error::new(std::io::ErrorKind::Other, "outer error"); - // std::io::Error 的 source 链需要手动构造,这里用 anyhow 风格的 context 模拟 - // 简化:验证无 source 时不拼接 "caused by" + let outer = OuterError::Wrapped(inner); let chain = format_error_chain(&outer); - assert!(chain.contains("outer error")); - assert!(!chain.contains("caused by")); - let _ = inner; // 抑制未使用警告 + assert!(chain.contains("outer wrapper")); + assert!(chain.contains("caused by")); + assert!(chain.contains("root cause")); } }