#[non_exhaustive]pub enum SourceMapError {
Oversize {
name: Box<str>,
len: u64,
},
SpaceExhausted {
needed: u64,
available: u64,
},
NotUtf8 {
name: Box<str>,
},
Io {
name: Box<str>,
kind: ErrorKind,
},
}Expand description
The reason a source could not be added to a SourceMap.
Adding a source can fail four ways, each a distinct, defined outcome rather than a panic or a silent corruption of the coordinate bookkeeping:
- the source is larger than the map’s per-source ceiling
(
Oversize), - it does not fit in what remains of the shared 32-bit position space
(
SpaceExhausted), - its bytes are not valid UTF-8 (
NotUtf8), or - the file behind a path could not be read (
Io,stdonly).
Every variant names the source it concerns so the failure is actionable when it is logged far from the call that produced it.
The enum is #[non_exhaustive]: a downstream match must include a wildcard
arm, so later additions never force a breaking change on callers.
§Examples
use source_lang::{SourceMap, SourceMapError};
let mut map = SourceMap::new();
// Raw bytes that are not valid UTF-8 are rejected, naming the source.
let err = map.add_bytes("blob.bin", &[0xff, 0xfe]).unwrap_err();
assert!(matches!(err, SourceMapError::NotUtf8 { .. }));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Oversize
The source is larger than the map’s configured per-source ceiling.
The ceiling defaults to u32::MAX — the addressing limit of the global
position space — and can be lowered with
SourceMap::set_max_source_len to
bound how much a single untrusted input may load. For a file, the size is
checked against the path’s metadata before the bytes are read, so an
oversize file is never pulled into memory.
Fields
SpaceExhausted
The source did not fit in what remained of the map’s global space.
Returned when the source is no larger than the per-source ceiling but still exceeds the bytes left in the shared 32-bit position space — because earlier sources have consumed the remainder — or when the map already holds the maximum number of sources. The map is left unchanged, so the caller may start a fresh map or split the input.
Fields
NotUtf8
The source’s bytes are not valid UTF-8.
A SourceMap stores text, so input from
add_bytes or a file is validated before
it is stored. A truncated multi-byte sequence or stray binary byte is
reported here rather than stored as corrupt text.
Io
std only.A file’s contents could not be read from disk.
Returned by add_file when opening or
reading the path fails — a missing file, a directory, or a permission
error. The std::io::ErrorKind distinguishes the cause without carrying
a non-comparable std::io::Error, so this variant stays Clone and
Eq like the rest.
Trait Implementations§
Source§impl Clone for SourceMapError
impl Clone for SourceMapError
Source§fn clone(&self) -> SourceMapError
fn clone(&self) -> SourceMapError
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SourceMapError
impl Debug for SourceMapError
Source§impl Display for SourceMapError
impl Display for SourceMapError
impl Eq for SourceMapError
Source§impl Error for SourceMapError
impl Error for SourceMapError
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()
Source§impl PartialEq for SourceMapError
impl PartialEq for SourceMapError
Source§fn eq(&self, other: &SourceMapError) -> bool
fn eq(&self, other: &SourceMapError) -> bool
self and other values to be equal, and is used by ==.