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 9475456 feat: Suggest `boolean` when `bool` is used (#459)
9475456 is described below
commit 9475456cfe1e13439024d357a1c64679d4ee40e8
Author: Kriskras99 <[email protected]>
AuthorDate: Wed Feb 11 12:33:25 2026 +0100
feat: Suggest `boolean` when `bool` is used (#459)
* feat: Suggest `boolean` when `bool` is used
* feat: Improve error message
Co-authored-by: Martin Grigorov <[email protected]>
---------
Co-authored-by: Martin Grigorov <[email protected]>
---
avro/src/error.rs | 3 +++
avro/src/schema/mod.rs | 21 +++++++++++++++++++++
avro/src/schema/parser.rs | 9 ++++++++-
3 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/avro/src/error.rs b/avro/src/error.rs
index ea81125..e2dfa28 100644
--- a/avro/src/error.rs
+++ b/avro/src/error.rs
@@ -358,6 +358,9 @@ pub enum Details {
#[error("Unknown primitive type: {0}")]
ParsePrimitive(String),
+ #[error("Unknown primitive type: '{0}'. Did you mean '{1}' ?")]
+ ParsePrimitiveSimilar(String, &'static str),
+
#[error("invalid JSON for {key:?}: {value:?}")]
GetDecimalMetadataValueFromJson {
key: String,
diff --git a/avro/src/schema/mod.rs b/avro/src/schema/mod.rs
index e2d67a3..b283731 100644
--- a/avro/src/schema/mod.rs
+++ b/avro/src/schema/mod.rs
@@ -5128,4 +5128,25 @@ mod tests {
);
Ok(())
}
+
+ #[test]
+ fn avro_rs_456_bool_instead_of_boolean() -> TestResult {
+ let error = Schema::parse_str(
+ r#"{
+ "type": "record",
+ "name": "defaults",
+ "fields": [
+ {"name": "boolean", "type": "bool", "default": true}
+ ]
+ }"#,
+ )
+ .unwrap_err()
+ .into_details()
+ .to_string();
+ assert_eq!(
+ error,
+ Details::ParsePrimitiveSimilar("bool".to_string(),
"boolean").to_string()
+ );
+ Ok(())
+ }
}
diff --git a/avro/src/schema/parser.rs b/avro/src/schema/parser.rs
index 704f56b..eb1b849 100644
--- a/avro/src/schema/parser.rs
+++ b/avro/src/schema/parser.rs
@@ -187,7 +187,14 @@ impl Parser {
.input_schemas
.remove(&fully_qualified_name)
// TODO make a better descriptive error message here that conveys
that a named schema cannot be found
- .ok_or_else(||
Details::ParsePrimitive(fully_qualified_name.fullname(None)))?;
+ .ok_or_else(|| {
+ let full_name = fully_qualified_name.fullname(None);
+ if full_name == "bool" {
+ Details::ParsePrimitiveSimilar(full_name, "boolean")
+ } else {
+ Details::ParsePrimitive(full_name)
+ }
+ })?;
// parsing a full schema from inside another schema. Other full schema
will not inherit namespace
let parsed = self.parse(&value, &None)?;