Trusted. Error
(Cure Standard Library v0.38.0)
View Source
Error reasons shared by the trusted (unproved) standard library.
Why this module exists
The trusted layer is the second-level standard library: operations that
cannot be proved total — file I/O, the clock, entropy, the environment.
Their failures are real, so they must be in the type rather than left to
a runtime crash. FileError is that type for the filesystem.
The open tail
IoError(Atom) is deliberate. OTP's POSIX reason set is open — it varies
by platform and by OTP release — so a closed ADT would be a lie the first
time a new reason appeared. Everything Trusted.File can actually
distinguish is enumerated; the rest is carried verbatim so a caller that
needs :emfile or :eloop can still see it.
Examples
mod ErrorExample
use Trusted.Error
fn missing() -> FileError = classify(:enoent)
fn denied() -> FileError = classify(:eacces)
fn unknown() -> FileError = classify(:emfile)mod ErrorMatchExample
use Trusted.Error
fn describe_kind(reason: Atom) -> String =
match classify(reason)
IsDirectory() -> "that is a directory"
_ -> "something else"
Summary
Types
Why a trusted filesystem operation failed.
Functions
Map a raw OTP reason atom to its FileError constructor.
A short, stable English description of a FileError.
Types
enum FileError
NotFound
PermissionDenied
IsDirectory
NotDirectory
AlreadyExists
NoSpace
InvalidUtf8
IoError
Why a trusted filesystem operation failed.
The first seven constructors are the reasons Trusted.File maps
explicitly; IoError carries every other POSIX atom unchanged.
Functions
fn classify(reason: Atom) -> FileError
Map a raw OTP reason atom to its FileError constructor.
Total: an unknown atom becomes IoError(atom) rather than raising, so a
platform-specific reason can never turn a handled failure into a crash.
Examples
mod ClassifyExample
use Trusted.Error
fn missing() -> FileError = classify(:enoent)
fn denied() -> FileError = classify(:eacces)
fn unknown() -> FileError = classify(:ewhatever)
fn describe(error: FileError) -> String
A short, stable English description of a FileError.
Intended for log lines and CLI output, not for program logic: match on the constructor instead when the distinction matters.
Examples
mod DescribeExample
use Trusted.Error
fn missing() -> String = describe(NotFound())
fn carried() -> String = describe(IoError(:emfile))