This is an automated email from the ASF dual-hosted git repository.
mgrigorov 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 bd1910d fix: Improve the error message for unresolved union variant
(#228)
bd1910d is described below
commit bd1910d0cedeeb16d08f9257bf4034aa1d7ba4e5
Author: Martin Grigorov <[email protected]>
AuthorDate: Thu Jul 17 21:06:38 2025 +0300
fix: Improve the error message for unresolved union variant (#228)
---
avro/src/error.rs | 6 +++---
avro/src/types.rs | 5 ++++-
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/avro/src/error.rs b/avro/src/error.rs
index e68495c..e28fa9d 100644
--- a/avro/src/error.rs
+++ b/avro/src/error.rs
@@ -16,7 +16,7 @@
// under the License.
use crate::{
- schema::{Name, Schema, SchemaKind},
+ schema::{Name, Schema, SchemaKind, UnionSchema},
types::{Value, ValueKind},
};
use std::{error::Error as _, fmt};
@@ -223,8 +223,8 @@ pub enum Error {
#[error("Key {0} not found in decimal metadata JSON")]
GetDecimalMetadataFromJson(&'static str),
- #[error("Could not find matching type in union")]
- FindUnionVariant,
+ #[error("Could not find matching type in {schema:?} for {value:?}")]
+ FindUnionVariant { schema: UnionSchema, value: Value },
#[error("Union type should not be empty")]
EmptyUnion,
diff --git a/avro/src/types.rs b/avro/src/types.rs
index f241661..2c5bdb0 100644
--- a/avro/src/types.rs
+++ b/avro/src/types.rs
@@ -1045,7 +1045,10 @@ impl Value {
};
let (i, inner) = schema
.find_schema_with_known_schemata(&v, Some(names),
enclosing_namespace)
- .ok_or(Error::FindUnionVariant)?;
+ .ok_or(Error::FindUnionVariant {
+ schema: schema.clone(),
+ value: v.clone(),
+ })?;
Ok(Value::Union(
i as u32,