Skip to content

Commit bd1910d

Browse files
authored
fix: Improve the error message for unresolved union variant (#228)
1 parent d8bc430 commit bd1910d

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

avro/src/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// under the License.
1717

1818
use crate::{
19-
schema::{Name, Schema, SchemaKind},
19+
schema::{Name, Schema, SchemaKind, UnionSchema},
2020
types::{Value, ValueKind},
2121
};
2222
use std::{error::Error as _, fmt};
@@ -223,8 +223,8 @@ pub enum Error {
223223
#[error("Key {0} not found in decimal metadata JSON")]
224224
GetDecimalMetadataFromJson(&'static str),
225225

226-
#[error("Could not find matching type in union")]
227-
FindUnionVariant,
226+
#[error("Could not find matching type in {schema:?} for {value:?}")]
227+
FindUnionVariant { schema: UnionSchema, value: Value },
228228

229229
#[error("Union type should not be empty")]
230230
EmptyUnion,

avro/src/types.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,10 @@ impl Value {
10451045
};
10461046
let (i, inner) = schema
10471047
.find_schema_with_known_schemata(&v, Some(names), enclosing_namespace)
1048-
.ok_or(Error::FindUnionVariant)?;
1048+
.ok_or(Error::FindUnionVariant {
1049+
schema: schema.clone(),
1050+
value: v.clone(),
1051+
})?;
10491052

10501053
Ok(Value::Union(
10511054
i as u32,

0 commit comments

Comments
 (0)