@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 40 lines 1.84 KB
Raw
1 import { assert, describe, it } from "@effect/vitest"
2 import { SystemError, type SystemErrorTag } from "effect/PlatformError"
3 import { handleError } from "../../src/internal/error.ts"
4
5 const withCode = (error: Error, code: string): Error & { readonly code: string } => Object.assign(error, { code })
6
7 describe("handleError", () => {
8 const mapError = handleError("FileSystem", "test", "/tmp/test")
9 const cases: ReadonlyArray<readonly [error: Error, tag: SystemErrorTag]> = [
10 [withCode(new Deno.errors.NotFound(), "ENOENT"), "NotFound"],
11 [withCode(new Deno.errors.NotADirectory(), "ENOTDIR"), "BadResource"],
12 [new Deno.errors.AlreadyExists(), "AlreadyExists"],
13 [withCode(new Deno.errors.AlreadyExists(), "EEXIST"), "AlreadyExists"],
14 [withCode(new Deno.errors.IsADirectory(), "EISDIR"), "BadResource"],
15 [withCode(new Deno.errors.PermissionDenied(), "EACCES"), "PermissionDenied"],
16 [withCode(new Error("operation not permitted"), "EPERM"), "PermissionDenied"],
17 [new Deno.errors.NotCapable(), "PermissionDenied"],
18 [new Deno.errors.BadResource(), "BadResource"],
19 [new Deno.errors.InvalidData(), "InvalidData"],
20 [new Deno.errors.TimedOut(), "TimedOut"],
21 [new Deno.errors.UnexpectedEof(), "UnexpectedEof"],
22 [new Deno.errors.WouldBlock(), "WouldBlock"],
23 [new Deno.errors.WriteZero(), "WriteZero"],
24 [new Error("unrecognised"), "Unknown"]
25 ]
26
27 for (const [error, tag] of cases) {
28 it(`maps ${error.name} to ${tag}`, () => {
29 const platformError = mapError(error)
30 const reason = platformError.reason
31
32 assert(reason instanceof SystemError)
33 assert.strictEqual(reason._tag, tag)
34 assert.strictEqual(reason.module, "FileSystem")
35 assert.strictEqual(reason.method, "test")
36 assert.strictEqual(reason.pathOrDescriptor, "/tmp/test")
37 assert.strictEqual(reason.cause, error)
38 })
39 }
40 })