Skip to content

Commit 8a9e0a3

Browse files
committed
feat: enforce tagged error messages
1 parent f0ebd89 commit 8a9e0a3

33 files changed

Lines changed: 468 additions & 48 deletions

File tree

‎.github/workflows/lint.yml‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: lint
2+
3+
on:
4+
push:
5+
branches: [dev]
6+
pull_request:
7+
workflow_dispatch:
8+
9+
jobs:
10+
lint:
11+
runs-on: blacksmith-4vcpu-ubuntu-2404
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
15+
16+
- name: Setup Bun
17+
uses: ./.github/actions/setup-bun
18+
19+
- name: Test lint rules
20+
run: bun lint:test
21+
22+
- name: Run lint
23+
run: bun lint --quiet

‎.oxlintrc.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/nicolo-ribaudo/oxc-project.github.io/refs/heads/json-schema/src/public/.oxlintrc.schema.json",
3+
"jsPlugins": ["./script/lint/opencode.mjs"],
34
"options": {
45
"typeAware": true
56
},
67
"categories": {
78
"suspicious": "warn"
89
},
910
"rules": {
11+
"opencode/tagged-error-message": "error",
1012
"typescript/no-base-to-string": "warn",
1113
// Effect uses `function*` with Effect.gen/Effect.fnUntraced that don't always yield
1214
"require-yield": "off",
@@ -47,5 +49,5 @@
4749
"options": {
4850
"typeAware": true
4951
},
50-
"ignorePatterns": ["**/node_modules", "**/dist", "**/.build", "**/.sst", "**/*.d.ts", "**/sdk.gen.ts"]
52+
"ignorePatterns": ["**/node_modules", "**/dist", "**/.build", "**/.sst", "**/.lint-tmp-*", "**/*.d.ts", "**/sdk.gen.ts"]
5153
}

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"dev:stats": "bun sst shell --stage=production -- bun run --cwd packages/stats/app dev",
1414
"dev:storybook": "bun --cwd packages/storybook storybook",
1515
"lint": "oxlint",
16+
"lint:test": "bun script/lint/test.ts",
1617
"typecheck": "bun turbo typecheck",
1718
"upgrade-opentui": "bun run script/upgrade-opentui.ts",
1819
"postinstall": "bun run --cwd packages/core fix-node-pty",

‎packages/core/src/aisdk.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Cause, Context, Effect, Layer, Schema, Scope } from "effect"
55
import { ModelV2 } from "./model"
66
import { ProviderV2 } from "./provider"
77
import { State } from "./state"
8+
import { errorMessage } from "./util/error"
89

910
type SDK = any
1011

@@ -123,7 +124,11 @@ function prepareOptions(model: ModelV2.Info, pkg: string) {
123124
export class InitError extends Schema.TaggedErrorClass<InitError>()("AISDK.InitError", {
124125
providerID: ProviderV2.ID,
125126
cause: Schema.Defect(),
126-
}) {}
127+
}) {
128+
override get message() {
129+
return `Failed to initialize AI SDK provider ${this.providerID}: ${errorMessage(this.cause)}`
130+
}
131+
}
127132

128133
function initError(providerID: ProviderV2.ID) {
129134
return Effect.catchCause((cause) => Effect.fail(new InitError({ providerID, cause: Cause.squash(cause) })))

‎packages/core/src/control-plane/move-session.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ export class DestinationProjectMismatchError extends Schema.TaggedErrorClass<Des
3030
expected: ProjectV2.ID,
3131
actual: ProjectV2.ID,
3232
},
33-
) {}
33+
) {
34+
override get message() {
35+
return `Destination project ${this.actual} does not match session project ${this.expected}`
36+
}
37+
}
3438

3539
export class ApplyChangesError extends Schema.TaggedErrorClass<ApplyChangesError>()("MoveSession.ApplyChangesError", {
3640
message: Schema.String,

‎packages/core/src/file-mutation.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,19 @@ export interface RemoveInput {
3030

3131
export class StaleContentError extends Schema.TaggedErrorClass<StaleContentError>()("FileMutation.StaleContentError", {
3232
path: Schema.String,
33-
}) {}
33+
}) {
34+
override get message() {
35+
return `File changed since it was read: ${this.path}`
36+
}
37+
}
3438

3539
export class TargetExistsError extends Schema.TaggedErrorClass<TargetExistsError>()("FileMutation.TargetExistsError", {
3640
path: Schema.String,
37-
}) {}
41+
}) {
42+
override get message() {
43+
return `File already exists: ${this.path}`
44+
}
45+
}
3846

3947
export interface WriteResult {
4048
readonly operation: "write"

‎packages/core/src/image.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import { FileSystem } from "./filesystem"
77
export class ResizerUnavailableError extends Schema.TaggedErrorClass<ResizerUnavailableError>()(
88
"Image.ResizerUnavailableError",
99
{},
10-
) {}
10+
) {
11+
override get message() {
12+
return "Image resizer is unavailable"
13+
}
14+
}
1115

1216
export class DecodeError extends Schema.TaggedErrorClass<DecodeError>()("Image.DecodeError", {
1317
resource: Schema.String,

‎packages/core/src/integration.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { State } from "./state"
2020
import { Identifier } from "./util/identifier"
2121
import { EventV2 } from "./event"
2222
import { IntegrationConnection } from "./integration/connection"
23-
import { causeMessage } from "./util/error"
23+
import { causeMessage, errorMessage } from "./util/error"
2424

2525
export const ID = IntegrationSchema.ID
2626
export type ID = IntegrationSchema.ID
@@ -165,11 +165,19 @@ export type AttemptStatus = typeof AttemptStatus.Type
165165

166166
export class CodeRequiredError extends Schema.TaggedErrorClass<CodeRequiredError>()("Integration.CodeRequired", {
167167
attemptID: AttemptID,
168-
}) {}
168+
}) {
169+
override get message() {
170+
return `Authorization code required for OAuth attempt ${this.attemptID}`
171+
}
172+
}
169173

170174
export class AuthorizationError extends Schema.TaggedErrorClass<AuthorizationError>()("Integration.Authorization", {
171175
cause: Schema.Defect(),
172-
}) {}
176+
}) {
177+
override get message() {
178+
return `Integration authorization failed: ${errorMessage(this.cause)}`
179+
}
180+
}
173181

174182
export type Error = CodeRequiredError | AuthorizationError
175183

‎packages/core/src/location-mutation.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ export type ResolveInput = typeof ResolveInput.Type
2323
export class PathError extends Schema.TaggedErrorClass<PathError>()("LocationMutation.PathError", {
2424
path: Schema.String,
2525
reason: Schema.Literals(["relative_escape", "location_escape", "non_directory_ancestor"]),
26-
}) {}
26+
}) {
27+
override get message() {
28+
if (this.reason === "relative_escape") return `Relative path escapes the location: ${this.path}`
29+
if (this.reason === "location_escape") return `Path resolves outside the location: ${this.path}`
30+
return `Path has a non-directory ancestor: ${this.path}`
31+
}
32+
}
2733

2834
export interface ExternalDirectoryAuthorization {
2935
readonly action: "external_directory"

‎packages/core/src/npm.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,18 @@ import { LayerNode } from "./effect/layer-node"
1111
import { filesystem } from "./effect/layer-node-platform"
1212
import { makeRuntime } from "./effect/runtime"
1313
import { NpmConfig } from "./npm-config"
14+
import { errorMessage } from "./util/error"
1415

1516
export class InstallFailedError extends Schema.TaggedErrorClass<InstallFailedError>()("NpmInstallFailedError", {
1617
add: Schema.Array(Schema.String).pipe(Schema.optional),
1718
dir: Schema.String,
1819
cause: Schema.optional(Schema.Defect()),
19-
}) {}
20+
}) {
21+
override get message() {
22+
const detail = this.cause === undefined ? undefined : errorMessage(this.cause)
23+
return `Failed to install ${this.add?.join(", ") || "dependencies"} in ${this.dir}${detail ? `: ${detail}` : ""}`
24+
}
25+
}
2026

2127
export interface EntryPoint {
2228
readonly directory: string

0 commit comments

Comments
 (0)