pub enum JsonConversionError {
Show 13 variants
ParseError(String),
InvalidRoot(String),
InvalidNumber(String),
InvalidExpression(String),
InvalidTensor,
NestedObject,
InvalidReference(String),
InvalidUnicode(String),
MaxDepthExceeded(usize),
MaxArraySizeExceeded(usize, usize),
MaxStringLengthExceeded(usize, usize),
MaxObjectSizeExceeded(usize, usize),
IntegerOverflow {
value: String,
max: i64,
min: i64,
},
}Expand description
Errors that can occur during JSON to HEDL conversion
Variants§
ParseError(String)
JSON parsing failed
InvalidRoot(String)
Root value must be an object
InvalidNumber(String)
Invalid number value
InvalidExpression(String)
Invalid expression syntax
InvalidTensor
Invalid tensor element
NestedObject
Nested objects not allowed in scalar context
InvalidReference(String)
Reference parsing failed
InvalidUnicode(String)
Invalid Unicode encoding
This error occurs when JSON contains invalid Unicode sequences, such as:
- Unpaired UTF-16 surrogates (
\uD83Dwithout its low surrogate pair) - Invalid surrogate pairs (low surrogate before high surrogate)
- Unescaped control characters in strings
§UTF-16 Surrogate Background
JSON’s \uXXXX escapes use UTF-16 encoding. Characters outside the
Basic Multilingual Plane (U+10000 and above, including emoji) require
surrogate pairs: a high surrogate (0xD800-0xDBFF) followed by a low
surrogate (0xDC00-0xDFFF).
§Solutions
-
Use the
SurrogatePolicy::ReplaceWithFFFDoption: Replace invalid surrogates with the Unicode replacement character. -
Preprocess the JSON to fix or remove invalid sequences.
-
Ensure the source system produces valid UTF-8/UTF-16 pairs.
MaxDepthExceeded(usize)
Maximum recursion depth exceeded
MaxArraySizeExceeded(usize, usize)
Maximum array size exceeded
MaxStringLengthExceeded(usize, usize)
Maximum string length exceeded
MaxObjectSizeExceeded(usize, usize)
Maximum object size exceeded
IntegerOverflow
Integer value outside i64 range
JSON supports arbitrary-precision numbers, but HEDL’s Value::Int
uses i64 which has a fixed range: -9,223,372,036,854,775,808 to
9,223,372,036,854,775,807.
§Common Causes
- Twitter/Snowflake IDs (often exceed
i64::MAX) - Unsigned 64-bit integers from other systems
- Large database auto-increment IDs
- Timestamps in nanoseconds beyond year 2262
§Solutions
-
Use strings for large IDs (recommended):
{"tweet_id": "18446744073709551615"} -
Use hex encoding:
{"large_number": "0xFFFFFFFFFFFFFFFF"} -
Split into high/low parts:
{"value_high": 1844674407, "value_low": 3709551615}
§Examples
use hedl_json::{from_json, FromJsonConfig};
let json = r#"{"id": 18446744073709551615}"#;
let result = from_json(json, &FromJsonConfig::default());
assert!(result.is_err());
assert!(result.unwrap_err().to_string().contains("Integer overflow"));Trait Implementations§
Source§impl Clone for JsonConversionError
impl Clone for JsonConversionError
Source§fn clone(&self) -> JsonConversionError
fn clone(&self) -> JsonConversionError
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for JsonConversionError
impl Debug for JsonConversionError
Source§impl Display for JsonConversionError
impl Display for JsonConversionError
Source§impl Error for JsonConversionError
impl Error for JsonConversionError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§impl From<Error> for JsonConversionError
impl From<Error> for JsonConversionError
Source§impl From<JsonConversionError> for StreamError
impl From<JsonConversionError> for StreamError
Source§fn from(source: JsonConversionError) -> Self
fn from(source: JsonConversionError) -> Self
Auto Trait Implementations§
impl Freeze for JsonConversionError
impl RefUnwindSafe for JsonConversionError
impl Send for JsonConversionError
impl Sync for JsonConversionError
impl Unpin for JsonConversionError
impl UnwindSafe for JsonConversionError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.