This is an automated email from the ASF dual-hosted git repository.

kriskras99 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/avro-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new 1d2ba7c  fix: Print the Debug impl of TestError for more info (#393)
1d2ba7c is described below

commit 1d2ba7c0d87b79651e6e62023e3b656490d123fc
Author: Martin Grigorov <[email protected]>
AuthorDate: Thu Jan 8 09:48:12 2026 +0200

    fix: Print the Debug impl of TestError for more info (#393)
    
    * fix: Print the Debug impl of TestError for more info
    
    Fixes #370
    
    Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
    
    * Use TestResult for two tests in schema.rs
    
    Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
    
    * Drop the dependency on anyhow for avro_test_helper
    
    Nothing from anyhow was used anyway
    
    * Add a comment why Display impl is required - to filter out TestError 
itself
    
    ---------
    
    Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
---
 Cargo.lock                  |  1 -
 avro/src/schema.rs          | 22 ++++++++++++----------
 avro_test_helper/Cargo.toml |  1 -
 avro_test_helper/src/lib.rs | 10 ++++++----
 4 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index 7cd1402..3d580e2 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -111,7 +111,6 @@ dependencies = [
 name = "apache-avro-test-helper"
 version = "0.22.0"
 dependencies = [
- "anyhow",
  "better-panic",
  "ctor",
  "env_logger",
diff --git a/avro/src/schema.rs b/avro/src/schema.rs
index 9d988c8..cba069b 100644
--- a/avro/src/schema.rs
+++ b/avro/src/schema.rs
@@ -7470,7 +7470,7 @@ mod tests {
     }
 
     #[test]
-    fn avro_rs_339_schema_ref_uuid() {
+    fn avro_rs_339_schema_ref_uuid() -> TestResult {
         let schema = Schema::parse_str(
             r#"{
             "name": "foo",
@@ -7491,14 +7491,15 @@ mod tests {
                 }
             ]
         }"#,
-        )
-        .unwrap();
-        let _resolved = ResolvedSchema::try_from(&schema).unwrap();
-        let _resolved_owned = ResolvedOwnedSchema::try_from(schema).unwrap();
+        )?;
+        let _resolved = ResolvedSchema::try_from(&schema)?;
+        let _resolved_owned = ResolvedOwnedSchema::try_from(schema)?;
+
+        Ok(())
     }
 
     #[test]
-    fn avro_rs_339_schema_ref_decimal() {
+    fn avro_rs_339_schema_ref_decimal() -> TestResult {
         let schema = Schema::parse_str(
             r#"{
             "name": "foo",
@@ -7521,10 +7522,11 @@ mod tests {
                 }
             ]
         }"#,
-        )
-        .unwrap();
-        let _resolved = ResolvedSchema::try_from(&schema).unwrap();
-        let _resolved_owned = ResolvedOwnedSchema::try_from(schema).unwrap();
+        )?;
+        let _resolved = ResolvedSchema::try_from(&schema)?;
+        let _resolved_owned = ResolvedOwnedSchema::try_from(schema)?;
+
+        Ok(())
     }
 
     #[test]
diff --git a/avro_test_helper/Cargo.toml b/avro_test_helper/Cargo.toml
index 6b28456..555fcf7 100644
--- a/avro_test_helper/Cargo.toml
+++ b/avro_test_helper/Cargo.toml
@@ -30,7 +30,6 @@ readme = "README.md"
 
 
 [dependencies]
-anyhow = { default-features = false, version = "1.0.100", features = ["std"] }
 better-panic = { default-features = false, version = "0.3.0" }
 ctor = { default-features = false, version = "0.6.3", features = ["dtor", 
"proc_macro"]  }
 env_logger = { default-features = false, version = "0.11.8" }
diff --git a/avro_test_helper/src/lib.rs b/avro_test_helper/src/lib.rs
index 8c570f5..6366a8e 100644
--- a/avro_test_helper/src/lib.rs
+++ b/avro_test_helper/src/lib.rs
@@ -51,19 +51,21 @@ fn after_all() {
 
 /// A custom error type for tests.
 #[derive(Debug)]
-pub struct TestError {}
+pub struct TestError;
 
 /// A converter of any error into [TestError].
 /// It is used to print better error messages in the tests.
 /// Borrowed from 
<https://bluxte.net/musings/2023/01/08/improving_failure_messages_rust_tests/>
-impl<Err: std::fmt::Display> From<Err> for TestError {
+// The Display bound is needed so that the `From` implementation doesn't
+// apply to `TestError` itself.
+impl<Err: std::fmt::Display + std::fmt::Debug> From<Err> for TestError {
     #[track_caller]
     fn from(err: Err) -> Self {
-        panic!("{}: {}", std::any::type_name::<Err>(), err);
+        panic!("{}: {:?}", std::any::type_name::<Err>(), err);
     }
 }
 
-pub type TestResult = anyhow::Result<(), TestError>;
+pub type TestResult = Result<(), TestError>;
 
 /// Does nothing. Just loads the crate.
 /// Should be used in the integration tests, because they do not use 
[dev-dependencies]

Reply via email to