Skip to content

Return INVALID_VALUE instead of BadRequest for integers out of range #5

Description

@RReverser

Now that we're limiting integers to real-world ranges (eg unsigned integers where it makes sense) more than the spec does, we have a slight mismatch in error codes that fails strict ConformU tests.

At this point we already have too many specializations in

self.0
.swap_remove(name.as_ref())
.map(|mut value| {
// Specialization: optimized path to avoid cloning the string.
if TypeId::of::<T>() == TypeId::of::<String>() {
return T::deserialize(value.into_deserializer());
}
// Specialization: booleans in ASCOM must be case-insensitive.
if TypeId::of::<T>() == TypeId::of::<bool>() {
value.make_ascii_lowercase();
}
serde_plain::from_str(&value)
})
and a proper fix would be rewriting that block to use a custom deserializer instead. It should port over the existing behaviour of booleans and strings, while for any integers it should try to parse as i32 (as per spec) first, map failures to BadRequest, and then do try_form to the target integer type, and map failures to INVALID_VALUE this time.

Originally reported at ivonnyssen/qhyccd-alpaca#26 (comment) by @ivonnyssen.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions