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>
| Variant | Meaning |
|---|---|
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::InvalidRange | start is greater than end |
Error::InvalidMtime | The file’s modification time cannot be represented as a UTC datetime |
Mismatch Variants
The Mismatch enum describes what specifically does not match:
| Variant | Meaning | Hint In Error Message |
|---|---|---|
Mismatch::Path | File path changed | “(resync the state if the file moved)” |
Mismatch::Size | File size changed | “(resync the state if this is expected)” |
Mismatch::Mtime | Modification time changed | “(resync the state if this is expected)” |
Mismatch::Missing | Tracked file no longer exists | “(resync the state if the file moved)” |
Mismatch::Identity | First bytes don’t match fingerprint | “(start over under a new state)” |
Mismatch::Checksum | State file was modified outside preader | |
Mismatch::Unsealed | State object has unsaved changes | “(pass the state returned by save())” |
Mismatch::Stale | State was saved elsewhere since last load | “(open a new iterator to continue)” |
Mismatch::Name | State file belongs to a different name |
NameError Variants
| Variant | Meaning |
|---|---|
NameError::Empty | The name is an empty string |
NameError::Escapes | The name starts with / or contains .. |
NameError::Invalid | The 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 Error | Python Exception |
|---|---|
Error::Io | OSError (or a subclass like PermissionError) |
Error::NotFound | KeyError |
Error::Alias | StateError |
Error::Corrupt | StateCorruptError |
Mismatch::Path | StateOutdatedError |
Mismatch::Size | StateOutdatedError |
Mismatch::Mtime | StateOutdatedError |
Mismatch::Missing | StateOutdatedError |
Mismatch::Checksum | StateCorruptError |
Mismatch::Name | StateCorruptError |
Mismatch::Identity | StateMismatchError |
Mismatch::Unsealed | StateMismatchError |
Mismatch::Stale | StateConflictError |
Error::Name | ValueError |
Error::InvalidRange | ValueError |
Error::InvalidMtime | ValueError |
Error::Utf8 | ValueError |
Error::Serde | ValueError |
Error::Regex | ValueError |
See Recovery Patterns for how to handle each error family