PlatformError.ts
PlatformError.ts overview
Section titled “PlatformError.ts overview”Normalized errors for platform APIs.
Platform services such as file systems, terminals, and sockets use
PlatformError to report host-level failures in a consistent shape. The
wrapper records whether the problem came from an invalid argument or from the
operating system, while preserving useful details such as the module, method,
path, descriptor, description, and original cause when available.
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”constructors
Section titled “constructors”badArgument
Section titled “badArgument”Creates a PlatformError whose reason is a BadArgument.
When to use
Use to report a platform API rejecting caller input before performing the underlying operation.
Signature
declare const badArgument: (options: { readonly module: string readonly method: string readonly description?: string | undefined readonly cause?: unknown}) => PlatformErrorSince v4.0.0
systemError
Section titled “systemError”Creates a PlatformError whose reason is a SystemError.
When to use
Use to adapt an operating-system or platform failure into the normalized platform error model.
Signature
declare const systemError: (options: { readonly _tag: SystemErrorTag readonly module: string readonly method: string readonly description?: string | undefined readonly syscall?: string | undefined readonly pathOrDescriptor?: string | number | undefined readonly cause?: unknown}) => PlatformErrorSince v4.0.0
models
Section titled “models”BadArgument (class)
Section titled “BadArgument (class)”Error data for an invalid argument passed to a platform API.
When to use
Use when you need to model caller input rejected before a platform operation runs, including invalid-argument reason data.
Details
The error records the module and method that rejected the argument, with an
optional description and cause. It is usually wrapped in PlatformError.
See
badArgumentfor creating a wrappedPlatformErrorwhose reason isBadArgumentSystemErrorfor failures reported by the host platform or operating systemPlatformErrorfor the wrapper used by most platform APIs
Signature
declare class BadArgumentSince v4.0.0
PlatformError (class)
Section titled “PlatformError (class)”Tagged error used by platform APIs to report either invalid arguments or system-level failures.
When to use
Use as the shared error type for platform APIs that expose invalid arguments
and host or operating-system failures through a single Effect error
channel.
Details
The reason field contains the underlying BadArgument or SystemError.
When that reason has a cause, the cause is preserved on the wrapper.
See
BadArgumentfor invalid inputs rejected before an operation runsSystemErrorfor failures reported by the host platform or operating systembadArgumentfor creating this wrapper from rejected caller inputsystemErrorfor creating this wrapper from a host or operating-system failure
Signature
declare class PlatformError { constructor(reason: BadArgument | SystemError)}Since v4.0.0
[TypeId] (property)
Section titled “[TypeId] (property)”Marks this value as a platform error wrapper for runtime guards.
When to use
Use to identify PlatformError values through their runtime type marker.
Signature
readonly [TypeId]: "~effect/platform/PlatformError"Since v4.0.0
SystemError (class)
Section titled “SystemError (class)”Error data for a platform or system operation failure.
When to use
Use when you need normalized reason data for a platform or system operation failure, including the operation details.
Details
The error records a normalized _tag, the module and method that failed,
and optional details such as the syscall, path or descriptor, description,
and original cause. It is usually wrapped in PlatformError.
See
systemErrorfor creating the usualPlatformErrorwrapper from this reason dataBadArgumentfor platform API failures caused by rejected caller input before an operation runsSystemErrorTagfor the normalized tag values stored in_tag
Signature
declare class SystemErrorSince v4.0.0
SystemErrorTag (type alias)
Section titled “SystemErrorTag (type alias)”Normalized category for failures reported by platform or system operations.
When to use
Use to type or match the normalized _tag on SystemError values reported
by platform operations.
Details
The tags group lower-level platform errors into a stable set such as
NotFound, PermissionDenied, TimedOut, and Unknown.
See
SystemErrorfor the error data that carries this tag on its_tagfieldsystemErrorfor creating aPlatformErrorfrom a system failure with one of these tags
Signature
type SystemErrorTag = | "AlreadyExists" | "BadResource" | "Busy" | "InvalidData" | "NotFound" | "PermissionDenied" | "TimedOut" | "UnexpectedEof" | "Unknown" | "WouldBlock" | "WriteZero"Since v4.0.0