#[non_exhaustive]pub enum FormError {
Limit {
limit: Limit,
at: Location,
},
Syntax {
reason: SyntaxError,
at: Location,
},
Encoding {
reason: EncodingError,
at: Location,
},
Policy {
reason: PolicyRefusal,
at: Location,
},
Refused {
refusal: Refusal,
at: Location,
},
Extract {
reason: ExtractError,
field: Option<&'static str>,
},
UnsupportedMediaType,
InvalidLimits {
limit: Limit,
},
BufferTooSmall {
needed: usize,
},
Io {
kind: ErrorKind,
},
Random,
Poisoned,
}Expand description
Everything that can go wrong in form-net.
Input errors (Limit, Syntax, Encoding, Policy) carry a
Location; caller mistakes (InvalidLimits, BufferTooSmall,
Poisoned) and environment failures (Io, Random) do not.
status_hint maps every error to an HTTP status and
code to a stable name.
§Examples
use form_net::{FormError, Limit};
let err = form_net::parse_urlencoded(&vec![b'a'; 11 << 20]).unwrap_err();
assert!(matches!(err, FormError::Limit { limit: Limit::Body, .. }));
assert_eq!((err.status_hint(), err.code()), (413, "limit.body"));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Limit
A budget of Limits was exceeded.
Syntax
The input breaks the grammar.
Encoding
Bytes that do not decode: percent escapes, UTF-8, charsets.
Policy
The input is well formed but a Policy refuses it.
Refused
An inspector refused the input.
Extract
Typed extraction failed.
Fields
reason: ExtractErrorWhat was wrong.
UnsupportedMediaType
The content type is not one form-net parses.
InvalidLimits
Limits::validate refused the
configuration.
BufferTooSmall
A buffer the caller provided is too short.
Io
std only.The reader, the writer, or the file system failed.
Random
std only.The operating system’s random source failed.
Poisoned
A parser was called again after an error, without reset.
Implementations§
Source§impl FormError
impl FormError
Sourcepub const fn status_hint(&self) -> u16
pub const fn status_hint(&self) -> u16
The HTTP status a server should answer with.
413 for every limit, 400 for syntax and most encoding and policy errors, 415 for unsupported media types, charsets, transfer encodings, and nested multipart, 422 for extraction errors, 503 when the shared spill budget is full, 500 for caller mistakes and environment failures, and the inspector’s own status for a refusal (400 if that status is outside 400 to 599).
§Examples
use form_net::FormError;
assert_eq!(FormError::UnsupportedMediaType.status_hint(), 415);
assert_eq!(FormError::Poisoned.status_hint(), 500);Sourcepub const fn code(&self) -> &'static str
pub const fn code(&self) -> &'static str
A stable, machine-readable name for the error: the variant and the
reason in snake case, joined with a dot (limit.parts,
syntax.boundary_in_content). A refusal returns the inspector’s own
Refusal::code. Codes never change meaning after 1.0.
§Examples
use form_net::FormError;
assert_eq!(FormError::UnsupportedMediaType.code(), "unsupported_media_type");
let err = form_net::parse_urlencoded(b"a=%zz").unwrap_err();
assert_eq!(err.code(), "encoding.invalid_percent");Sourcepub const fn location(&self) -> Option<Location>
pub const fn location(&self) -> Option<Location>
Where the error was found, for input errors and refusals.
§Examples
let err = form_net::parse_urlencoded(b"ok=1&bad=%zz").unwrap_err();
assert_eq!(err.location().map(|l| l.offset), Some(9));
assert_eq!(form_net::FormError::Poisoned.location(), None);Trait Implementations§
impl Copy for FormError
impl Eq for FormError
Source§impl Error for FormError
impl Error for FormError
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
use the Display impl or to_string()