/std
@thourum/fault/std provides small Result wrappers for JSON, files, and environment variables.
safeJsonParse
safeJsonParse<T = unknown>(text: string): Result<T, Fault>
safeJsonParse returns the parsed value or preserves the thrown cause with JSON.parse failed details.
Tag produced: PARSE_ERROR.
safeJsonStringify
safeJsonStringify(value: unknown, space?: number): Result<string, Fault>
safeJsonStringify treats circular values, BigInt, and an undefined JSON result as parse faults with JSON.stringify failed details.
Tag produced: PARSE_ERROR.
safeReadFile
safeReadFile(path: string, encoding: BufferEncoding = 'utf8'): ResultAsync<string, Fault>
safeReadFile records the file path and error code in metadata and maps filesystem codes with the table below.
Tags produced: NOT_FOUND, FORBIDDEN, or INTERNAL_ERROR.
safeWriteFile
safeWriteFile(path: string, data: string | Uint8Array): ResultAsync<void, Fault>
safeWriteFile uses the same filesystem tag mapping and metadata as safeReadFile.
Tags produced: NOT_FOUND, FORBIDDEN, or INTERNAL_ERROR.
safeEnv
safeEnv(name: string): Result<string, Fault>
safeEnv rejects missing and empty variables, including the variable name in metadata.
Tag produced: CONFIGURATION_ERROR.