Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Error Types

Rust

All errors are variants of the Error enum. Functions return preader::Result<T>, which is an alias for std::result::Result<T, Error>

VariantMeaning
Error::Io(e)An I/O error from the operating system
Error::Serde(e)Failed to parse or serialize a state file
Error::Regex(e)Invalid regex pattern in search()
Error::Utf8(e)A line contained invalid UTF-8
Error::Name(NameError)A state name violates the naming rules
Error::Mismatch { name, kind }File or state metadata does not match
Error::Corrupt { name, error }A state file is damaged or was edited
Error::Alias { name }A part of the state name is a symlink, case alias, or Unicode alias
Error::NotFound(name)No saved state with that name
Error::InvalidRangestart is greater than end
Error::InvalidMtimeThe file’s modification time cannot be represented as a UTC datetime

Mismatch Variants

The Mismatch enum describes what specifically does not match:

VariantMeaningHint In Error Message
Mismatch::PathFile path changed“(resync the state if the file moved)”
Mismatch::SizeFile size changed“(resync the state if this is expected)”
Mismatch::MtimeModification time changed“(resync the state if this is expected)”
Mismatch::MissingTracked file no longer exists“(resync the state if the file moved)”
Mismatch::IdentityFirst bytes don’t match fingerprint“(start over under a new state)”
Mismatch::ChecksumState file was modified outside preader
Mismatch::UnsealedState object has unsaved changes“(pass the state returned by save())”
Mismatch::StaleState was saved elsewhere since last load“(open a new iterator to continue)”
Mismatch::NameState file belongs to a different name

NameError Variants

VariantMeaning
NameError::EmptyThe name is an empty string
NameError::EscapesThe name starts with / or contains ..
NameError::InvalidThe name is too long, uses bad characters, or is a Windows device name

Python

Python Exceptions form a hierarchy:

Exception
  └── StateError
        ├── StateMismatchError
        │     └── StateOutdatedError
        ├── StateCorruptError
        └── StateConflictError

All exception classes have a name property that holds the state name involved

Rust to Python Mapping

Rust ErrorPython Exception
Error::IoOSError (or a subclass like PermissionError)
Error::NotFoundKeyError
Error::AliasStateError
Error::CorruptStateCorruptError
Mismatch::PathStateOutdatedError
Mismatch::SizeStateOutdatedError
Mismatch::MtimeStateOutdatedError
Mismatch::MissingStateOutdatedError
Mismatch::ChecksumStateCorruptError
Mismatch::NameStateCorruptError
Mismatch::IdentityStateMismatchError
Mismatch::UnsealedStateMismatchError
Mismatch::StaleStateConflictError
Error::NameValueError
Error::InvalidRangeValueError
Error::InvalidMtimeValueError
Error::Utf8ValueError
Error::SerdeValueError
Error::RegexValueError

See Recovery Patterns for how to handle each error family