diff --git a/typify-impl/src/value.rs b/typify-impl/src/value.rs index ac7bfc60..742708b9 100644 --- a/typify-impl/src/value.rs +++ b/typify-impl/src/value.rs @@ -142,17 +142,19 @@ impl TypeEntry { let text = value.to_string(); let type_path = syn::parse_str::(type_name).unwrap(); - // Deserialize the string to the type; the unwrap() is + // Deserialize the string to the type; the runtime expect() is // unfortunate, but unavoidable without getting in the // underpants of the serialized form of these built-in types. quote! { - ::serde_json::from_str::< #type_path >(#text).unwrap() + ::serde_json::from_str::< #type_path >(#text) + .expect("invalid default provided") } } TypeEntryDetails::JsonValue => { let text = value.to_string(); quote! { - ::serde_json::from_str::<::serde_json::Value>(#text).unwrap() + ::serde_json::from_str::<::serde_json::Value>(#text) + .expect("invalid default provided") } } TypeEntryDetails::Boolean => { @@ -564,7 +566,8 @@ mod tests { .map(|x| x.to_string()), Some( quote! { - ::serde_json::from_str::<::uuid::Uuid>("\"not-a-uuid\"").unwrap() + ::serde_json::from_str::<::uuid::Uuid>("\"not-a-uuid\"") + .expect("invalid default provided") } .to_string() ), diff --git a/typify-impl/tests/vega.out b/typify-impl/tests/vega.out index c4898a74..cdb59c94 100644 --- a/typify-impl/tests/vega.out +++ b/typify-impl/tests/vega.out @@ -44272,8 +44272,10 @@ pub enum VoronoiTransformExtent { impl ::std::default::Default for VoronoiTransformExtent { fn default() -> Self { VoronoiTransformExtent::Array([ - ::serde_json::from_str::<::serde_json::Value>("[-100000,-100000]").unwrap(), - ::serde_json::from_str::<::serde_json::Value>("[100000,100000]").unwrap(), + ::serde_json::from_str::<::serde_json::Value>("[-100000,-100000]") + .expect("invalid default provided"), + ::serde_json::from_str::<::serde_json::Value>("[100000,100000]") + .expect("invalid default provided"), ]) } } @@ -45762,8 +45764,10 @@ pub mod defaults { } pub(super) fn voronoi_transform_extent() -> super::VoronoiTransformExtent { super::VoronoiTransformExtent::Array([ - ::serde_json::from_str::<::serde_json::Value>("[-100000,-100000]").unwrap(), - ::serde_json::from_str::<::serde_json::Value>("[100000,100000]").unwrap(), + ::serde_json::from_str::<::serde_json::Value>("[-100000,-100000]") + .expect("invalid default provided"), + ::serde_json::from_str::<::serde_json::Value>("[100000,100000]") + .expect("invalid default provided"), ]) } pub(super) fn window_transform_frame() -> super::WindowTransformFrame { diff --git a/typify/tests/schemas/types-with-defaults.rs b/typify/tests/schemas/types-with-defaults.rs index e50d4f9e..5f434722 100644 --- a/typify/tests/schemas/types-with-defaults.rs +++ b/typify/tests/schemas/types-with-defaults.rs @@ -466,7 +466,7 @@ pub mod defaults { ::serde_json::from_str::<::chrono::DateTime<::chrono::offset::Utc>>( "\"1970-01-01T00:00:00Z\"", ) - .unwrap() + .expect("invalid default provided") } pub(super) fn mr_default_numbers_big_nullable() -> ::std::option::Option<::std::num::NonZeroU64> { @@ -474,12 +474,15 @@ pub mod defaults { } pub(super) fn test_bed_any() -> ::std::vec::Vec<::serde_json::Value> { vec![ - ::serde_json::from_str::<::serde_json::Value>("[8,6,7]").unwrap(), - ::serde_json::from_str::<::serde_json::Value>("[5,3,0,9]").unwrap(), + ::serde_json::from_str::<::serde_json::Value>("[8,6,7]") + .expect("invalid default provided"), + ::serde_json::from_str::<::serde_json::Value>("[5,3,0,9]") + .expect("invalid default provided"), ] } pub(super) fn test_bed_id() -> ::uuid::Uuid { - ::serde_json::from_str::<::uuid::Uuid>("\"abc123-is-this-a-uuid\"").unwrap() + ::serde_json::from_str::<::uuid::Uuid>("\"abc123-is-this-a-uuid\"") + .expect("invalid default provided") } pub(super) fn u_int_container_max_path() -> super::UInt { super::UInt(1_i64)