@punks/cli 2.6.1 → 3.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/AGENTS.md +1 -1
  2. package/README.md +42 -24
  3. package/dist/BASELINE_CHANGELOG.md +57 -0
  4. package/dist/CHANGELOG.md +80 -0
  5. package/dist/data/scripts/harness-projection/adapters/claude.d.mts +3 -0
  6. package/dist/data/scripts/harness-projection/adapters/claude.mjs +124 -0
  7. package/dist/data/scripts/harness-projection/adapters/codex.d.mts +3 -0
  8. package/dist/data/scripts/harness-projection/adapters/codex.mjs +137 -0
  9. package/dist/data/scripts/harness-projection/adapters/cursor.d.mts +5 -0
  10. package/dist/data/scripts/harness-projection/adapters/cursor.mjs +106 -0
  11. package/dist/data/scripts/harness-projection/adapters/opencode.d.mts +5 -0
  12. package/dist/data/scripts/harness-projection/adapters/opencode.mjs +100 -0
  13. package/dist/data/scripts/harness-projection/apply.d.mts +12 -0
  14. package/dist/data/scripts/harness-projection/apply.mjs +96 -0
  15. package/dist/data/scripts/harness-projection/core.d.mts +8 -0
  16. package/dist/data/scripts/harness-projection/core.mjs +239 -0
  17. package/dist/data/scripts/harness-projection/test-fixtures/application-context-plan.json +27 -0
  18. package/dist/data/scripts/harness-projection/test-fixtures/claude/actions.json +109 -0
  19. package/dist/data/scripts/harness-projection/test-fixtures/claude/context-plan.json +150 -0
  20. package/dist/data/scripts/harness-projection/test-fixtures/claude/matrix.json +23 -0
  21. package/dist/data/scripts/harness-projection/test-fixtures/claude/traces.json +15 -0
  22. package/dist/data/scripts/harness-projection/test-fixtures/codex/actions.json +124 -0
  23. package/dist/data/scripts/harness-projection/test-fixtures/codex/context-plan.json +150 -0
  24. package/dist/data/scripts/harness-projection/test-fixtures/codex/matrix.json +23 -0
  25. package/dist/data/scripts/harness-projection/test-fixtures/codex/traces.json +15 -0
  26. package/dist/data/scripts/harness-projection/test-fixtures/cursor/compiler-input.json +93 -0
  27. package/dist/data/scripts/harness-projection/test-fixtures/cursor/context-plan.json +108 -0
  28. package/dist/data/scripts/harness-projection/test-fixtures/cursor/matrix.json +19 -0
  29. package/dist/data/scripts/harness-projection/test-fixtures/cursor/projection.json +54 -0
  30. package/dist/data/scripts/harness-projection/test-fixtures/mixed-context-plan.json +35 -0
  31. package/dist/data/scripts/harness-projection/test-fixtures/opencode/compiler-input.json +93 -0
  32. package/dist/data/scripts/harness-projection/test-fixtures/opencode/context-plan.json +108 -0
  33. package/dist/data/scripts/harness-projection/test-fixtures/opencode/matrix.json +19 -0
  34. package/dist/data/scripts/harness-projection/test-fixtures/opencode/projection.json +51 -0
  35. package/dist/data/scripts/sync-subagents.mjs +1113 -33
  36. package/dist/data/subagents/manifest.mjs +5 -6
  37. package/dist/index.js +1373 -62672
  38. package/dist/skills/agnostic/docs/docs-onboarding/SKILL.md +1 -1
  39. package/dist/skills/agnostic/docs/docs-onboarding/references/artifact-contract.md +2 -2
  40. package/dist/skills/agnostic/planning/create-plan/SKILL.md +11 -10
  41. package/dist/skills/agnostic/planning/create-plan/references/grill-ambiguity.md +10 -31
  42. package/dist/skills/agnostic/planning/create-plan/references/plan-schema.md +2 -2
  43. package/dist/skills/agnostic/planning/create-spec/SKILL.md +3 -5
  44. package/dist/skills/agnostic/planning/create-spec/assets/SPEC-TEMPLATE.md +1 -0
  45. package/dist/skills/agnostic/planning/create-spec/references/backlog-sync.md +2 -2
  46. package/dist/skills/agnostic/planning/create-spec/references/grill-phase.md +4 -9
  47. package/dist/skills/agnostic/planning/create-spec/references/spec-quality-bar.md +1 -0
  48. package/dist/skills/agnostic/planning/implement-spec/references/lifecycle.md +1 -1
  49. package/dist/skills/agnostic/requirements/grilling/LICENSE +21 -0
  50. package/dist/skills/agnostic/requirements/grilling/SKILL.md +6 -30
  51. package/dist/skills/agnostic/requirements/grilling/UPSTREAM.md +16 -0
  52. package/dist/skills/agnostic/requirements/requirements-grill/SKILL.md +3 -5
  53. package/dist/skills/agnostic/requirements/requirements-grill/references/artifact-output.md +40 -16
  54. package/dist/skills/agnostic/requirements/requirements-grill/references/grilling-flow.md +3 -16
  55. package/dist/skills/agnostic/requirements/write-backlog/REFERENCE.md +21 -15
  56. package/dist/skills/agnostic/requirements/write-backlog/SKILL.md +14 -14
  57. package/dist/skills/agnostic/requirements/write-backlog/assets/concepts/backlog-model.md +28 -9
  58. package/dist/skills/agnostic/requirements/write-backlog/assets/providers/azure-devops-create-payload.md +45 -5
  59. package/dist/skills/agnostic/requirements/write-backlog/assets/providers/github-projects-create-payload.md +48 -28
  60. package/dist/skills/agnostic/requirements/write-backlog/assets/providers/linear-create-payload.md +22 -6
  61. package/dist/skills/agnostic/requirements/write-backlog/assets/providers/monday-create-payload.md +47 -22
  62. package/dist/skills/frameworks/effect/effect/LICENSE +21 -0
  63. package/dist/skills/frameworks/effect/effect/SKILL.md +100 -0
  64. package/dist/skills/frameworks/effect/effect/UPSTREAM.md +11 -0
  65. package/dist/skills/frameworks/effect/effect/references/CACHING.md +76 -0
  66. package/dist/skills/frameworks/effect/effect/references/CONFIG.md +67 -0
  67. package/dist/skills/frameworks/effect/effect/references/HTTP_CLIENTS.md +101 -0
  68. package/dist/skills/frameworks/effect/{effect-authoring/references/otel-patterns.md → effect/references/OBSERVABILITY.md} +4 -29
  69. package/dist/skills/frameworks/effect/effect/references/SCHEDULING.md +135 -0
  70. package/dist/skills/frameworks/effect/effect/references/SCHEMA.md +130 -0
  71. package/dist/skills/frameworks/effect/effect/references/SERVICES_LAYERS.md +168 -0
  72. package/dist/skills/frameworks/effect/effect/references/STREAMS.md +135 -0
  73. package/dist/skills/frameworks/effect/effect/references/TESTING.md +118 -0
  74. package/dist/skills/frameworks/effect/effect-backend-structure/SKILL.md +7 -8
  75. package/dist/skills/frameworks/effect/effect-recoverable-actions/SKILL.md +1 -1
  76. package/dist/skills/frameworks/nestjs/nestjs-best-practices/.gitignore +29 -0
  77. package/dist/skills/misc/secrets-cli/SKILL.md +54 -0
  78. package/dist/skills/misc/secrets-cli/references/command-reference.md +107 -0
  79. package/dist/skills/misc/secrets-cli/references/safety-and-errors.md +54 -0
  80. package/dist/skills/misc/secrets-cli/references/workflows.md +106 -0
  81. package/dist/skills/phases/design-phase/phases/grill.md +1 -1
  82. package/dist/skills/phases/requirements-phase/SKILL.md +2 -4
  83. package/dist/skills/phases/review-phase/REFERENCE.md +13 -5
  84. package/dist/skills/phases/review-phase/SKILL.md +3 -2
  85. package/package.json +1 -1
  86. package/dist/skills/agnostic/planning/create-spec/references/handoff.md +0 -47
  87. package/dist/skills/frameworks/effect/effect-authoring/SKILL.md +0 -116
  88. package/dist/skills/frameworks/effect/effect-authoring/references/branded-types.md +0 -98
  89. package/dist/skills/frameworks/effect/effect-authoring/references/effect-primitives.md +0 -144
  90. package/dist/skills/frameworks/effect/effect-authoring/references/error-patterns.md +0 -156
  91. package/dist/skills/frameworks/effect/effect-authoring/references/test-patterns.md +0 -146
  92. package/dist/skills/frameworks/effect/effect-best-practices/SKILL.md +0 -517
  93. package/dist/skills/frameworks/effect/effect-best-practices/references/anti-patterns.md +0 -392
  94. package/dist/skills/frameworks/effect/effect-best-practices/references/effect-atom-patterns.md +0 -653
  95. package/dist/skills/frameworks/effect/effect-best-practices/references/error-patterns.md +0 -464
  96. package/dist/skills/frameworks/effect/effect-best-practices/references/language-server.md +0 -287
  97. package/dist/skills/frameworks/effect/effect-best-practices/references/layer-patterns.md +0 -495
  98. package/dist/skills/frameworks/effect/effect-best-practices/references/observability-patterns.md +0 -342
  99. package/dist/skills/frameworks/effect/effect-best-practices/references/rpc-cluster-patterns.md +0 -418
  100. package/dist/skills/frameworks/effect/effect-best-practices/references/schema-patterns.md +0 -353
  101. package/dist/skills/frameworks/effect/effect-best-practices/references/service-patterns.md +0 -299
  102. /package/dist/skills/frameworks/effect/{effect-authoring/references/effect-atom-patterns.md → effect/references/EFFECT_ATOM.md} +0 -0
@@ -1,464 +0,0 @@
1
- # Error Patterns
2
-
3
- ## Why Explicit Error Types?
4
-
5
- Generic errors like `BadRequestError` or `NotFoundError` seem convenient but create problems:
6
-
7
- | Generic Error | Problems |
8
- |--------------|----------|
9
- | `NotFoundError` | Which resource? How should frontend recover? |
10
- | `BadRequestError` | What's invalid? Can user fix it? |
11
- | `UnauthorizedError` | Session expired? Wrong credentials? Missing permission? |
12
- | `InternalServerError` | Retryable? User action needed? |
13
-
14
- **Explicit errors enable:**
15
- 1. **Specific UI messages** - "Your session expired" vs generic "Unauthorized"
16
- 2. **Targeted recovery** - Refresh token vs show login page
17
- 3. **Better observability** - Group errors by specific type in dashboards
18
- 4. **Type-safe handling** - `catchTag("SessionExpiredError")` vs generic catch
19
-
20
- ### Anti-Pattern: Generic Error Mapping
21
-
22
- ```typescript
23
- // ❌ WRONG - Collapsing to generic HTTP errors
24
- export class NotFoundError extends Schema.TaggedError<NotFoundError>()(
25
- "NotFoundError",
26
- { message: Schema.String },
27
- HttpApiSchema.annotations({ status: 404 }),
28
- ) {}
29
-
30
- // At API boundaries:
31
- Effect.catchTags({
32
- UserNotFoundError: (err) => Effect.fail(new NotFoundError({ message: "Not found" })),
33
- ChannelNotFoundError: (err) => Effect.fail(new NotFoundError({ message: "Not found" })),
34
- MessageNotFoundError: (err) => Effect.fail(new NotFoundError({ message: "Not found" })),
35
- })
36
-
37
- // Frontend receives: { _tag: "NotFoundError", message: "Not found" }
38
- // - Can't show specific message ("User doesn't exist" vs "Channel was deleted")
39
- // - Can't take specific action (redirect to user search vs channel list)
40
- // - Debugging is harder (which resource was missing?)
41
- ```
42
-
43
- ```typescript
44
- // ✅ CORRECT - Keep explicit errors all the way to frontend
45
- export class UserNotFoundError extends Schema.TaggedError<UserNotFoundError>()(
46
- "UserNotFoundError",
47
- { userId: UserId, message: Schema.String },
48
- HttpApiSchema.annotations({ status: 404 }),
49
- ) {}
50
-
51
- export class ChannelNotFoundError extends Schema.TaggedError<ChannelNotFoundError>()(
52
- "ChannelNotFoundError",
53
- { channelId: ChannelId, message: Schema.String },
54
- HttpApiSchema.annotations({ status: 404 }),
55
- ) {}
56
-
57
- // Frontend can handle each case:
58
- Result.builder(result)
59
- .onErrorTag("UserNotFoundError", (err) => <UserNotFoundMessage userId={err.userId} />)
60
- .onErrorTag("ChannelNotFoundError", (err) => <ChannelDeletedMessage />)
61
- .onErrorTag("SessionExpiredError", () => <RedirectToLogin />)
62
- .render()
63
- ```
64
-
65
- ## Error Naming Conventions
66
-
67
- | Pattern | Example | Use For |
68
- |---------|---------|---------|
69
- | `{Entity}NotFoundError` | `UserNotFoundError`, `ChannelNotFoundError` | Resource lookups |
70
- | `{Entity}{Action}Error` | `UserCreateError`, `MessageUpdateError` | Mutations that fail |
71
- | `{Feature}Error` | `SessionExpiredError`, `RateLimitExceededError` | Feature-specific failures |
72
- | `{Integration}Error` | `WorkOSUserFetchError`, `StripePaymentError` | External service errors |
73
- | `Invalid{Field}Error` | `InvalidEmailError`, `InvalidPasswordError` | Validation failures |
74
-
75
- ### Rich Error Context
76
-
77
- Include context fields that help with debugging and UI handling:
78
-
79
- ```typescript
80
- // Entity errors → include entity ID
81
- export class UserNotFoundError extends Schema.TaggedError<UserNotFoundError>()(
82
- "UserNotFoundError",
83
- {
84
- userId: UserId, // Which user?
85
- message: Schema.String,
86
- },
87
- HttpApiSchema.annotations({ status: 404 }),
88
- ) {}
89
-
90
- // Action errors → include input that failed
91
- export class UserCreateError extends Schema.TaggedError<UserCreateError>()(
92
- "UserCreateError",
93
- {
94
- email: Schema.String, // What email failed?
95
- reason: Schema.String, // Why? "duplicate", "invalid domain"
96
- message: Schema.String,
97
- },
98
- HttpApiSchema.annotations({ status: 400 }),
99
- ) {}
100
-
101
- // Integration errors → include service name and retryable flag
102
- export class StripePaymentError extends Schema.TaggedError<StripePaymentError>()(
103
- "StripePaymentError",
104
- {
105
- stripeErrorCode: Schema.String,
106
- retryable: Schema.Boolean,
107
- message: Schema.String,
108
- },
109
- HttpApiSchema.annotations({ status: 402 }),
110
- ) {}
111
-
112
- // Auth errors → include expiry info
113
- export class SessionExpiredError extends Schema.TaggedError<SessionExpiredError>()(
114
- "SessionExpiredError",
115
- {
116
- sessionId: SessionId,
117
- expiredAt: Schema.DateTimeUtc,
118
- message: Schema.String,
119
- },
120
- HttpApiSchema.annotations({ status: 401 }),
121
- ) {}
122
- ```
123
-
124
- ## Schema.TaggedError for All Errors
125
-
126
- **Always use `Schema.TaggedError`** for defining errors. This provides:
127
-
128
- 1. **Serialization** - Errors can be sent over RPC/network
129
- 2. **Type safety** - `_tag` discriminator enables `catchTag`
130
- 3. **Consistent structure** - All errors have predictable shape
131
- 4. **HTTP status mapping** - Via `HttpApiSchema.annotations`
132
-
133
- ### Basic Error Definition
134
-
135
- ```typescript
136
- import { Schema } from "effect"
137
- import { HttpApiSchema } from "@effect/platform"
138
-
139
- export class UserNotFoundError extends Schema.TaggedError<UserNotFoundError>()(
140
- "UserNotFoundError",
141
- {
142
- userId: UserId,
143
- message: Schema.String,
144
- },
145
- HttpApiSchema.annotations({ status: 404 }),
146
- ) {}
147
-
148
- export class UserCreateError extends Schema.TaggedError<UserCreateError>()(
149
- "UserCreateError",
150
- {
151
- message: Schema.String,
152
- cause: Schema.optional(Schema.String),
153
- },
154
- HttpApiSchema.annotations({ status: 400 }),
155
- ) {}
156
-
157
- export class UnauthorizedError extends Schema.TaggedError<UnauthorizedError>()(
158
- "UnauthorizedError",
159
- {
160
- message: Schema.String,
161
- },
162
- HttpApiSchema.annotations({ status: 401 }),
163
- ) {}
164
-
165
- export class ForbiddenError extends Schema.TaggedError<ForbiddenError>()(
166
- "ForbiddenError",
167
- {
168
- message: Schema.String,
169
- requiredPermission: Schema.optional(Schema.String),
170
- },
171
- HttpApiSchema.annotations({ status: 403 }),
172
- ) {}
173
- ```
174
-
175
- ### Required Fields
176
-
177
- Every error should have:
178
- - `message: Schema.String` - Human-readable description
179
- - Relevant context fields (IDs, etc.)
180
- - Optional `cause: Schema.optional(Schema.String)` for error chains
181
-
182
- ## Error Handling with catchTag/catchTags
183
-
184
- **Never use `catchAll` or `mapError`** when you can use `catchTag`/`catchTags`. These preserve type information and enable precise error handling.
185
-
186
- ### catchTag for Single Error Types
187
-
188
- ```typescript
189
- const findUser = Effect.fn("UserService.findUser")(function* (id: UserId) {
190
- return yield* repo.findById(id).pipe(
191
- Effect.catchTag("DatabaseError", (err) =>
192
- Effect.fail(new UserNotFoundError({
193
- userId: id,
194
- message: `Database lookup failed: ${err.message}`,
195
- }))
196
- ),
197
- )
198
- })
199
- ```
200
-
201
- ### catchTags for Multiple Error Types
202
-
203
- ```typescript
204
- const processOrder = Effect.fn("OrderService.processOrder")(function* (input: OrderInput) {
205
- return yield* validateAndProcess(input).pipe(
206
- Effect.catchTags({
207
- ValidationError: (err) =>
208
- Effect.fail(new OrderValidationError({
209
- message: err.message,
210
- field: err.field,
211
- })),
212
- PaymentError: (err) =>
213
- Effect.fail(new OrderPaymentError({
214
- message: `Payment failed: ${err.message}`,
215
- code: err.code,
216
- })),
217
- InventoryError: (err) =>
218
- Effect.fail(new OrderInventoryError({
219
- productId: err.productId,
220
- message: "Insufficient inventory",
221
- })),
222
- }),
223
- )
224
- })
225
- ```
226
-
227
- ### Why Not catchAll?
228
-
229
- ```typescript
230
- // WRONG - Loses type information
231
- yield* effect.pipe(
232
- Effect.catchAll((err) =>
233
- Effect.fail(new InternalServerError({ message: "Something failed" }))
234
- )
235
- )
236
-
237
- // Problems:
238
- // 1. Can't distinguish error types downstream
239
- // 2. Hides useful error context
240
- // 3. Makes debugging harder
241
- // 4. Frontend can't show specific messages
242
- ```
243
-
244
- ## Error Remapping Pattern
245
-
246
- Create reusable error remapping functions for common transformations:
247
-
248
- ```typescript
249
- import { Effect } from "effect"
250
-
251
- export const withRemapDbErrors = <A, E, R>(
252
- effect: Effect.Effect<A, E | DatabaseError | ConnectionError, R>,
253
- context: { entityType: string; entityId: string }
254
- ): Effect.Effect<A, E | EntityNotFoundError | ServiceUnavailableError, R> =>
255
- effect.pipe(
256
- Effect.catchTag("DatabaseError", (err) =>
257
- Effect.fail(new EntityNotFoundError({
258
- entityType: context.entityType,
259
- entityId: context.entityId,
260
- message: `${context.entityType} not found`,
261
- }))
262
- ),
263
- Effect.catchTag("ConnectionError", (err) =>
264
- Effect.fail(new ServiceUnavailableError({
265
- message: "Database connection unavailable",
266
- cause: err.message,
267
- }))
268
- ),
269
- )
270
-
271
- // Usage
272
- const findUser = Effect.fn("UserService.findUser")(function* (id: UserId) {
273
- return yield* repo.findById(id).pipe(
274
- withRemapDbErrors({ entityType: "User", entityId: id })
275
- )
276
- })
277
- ```
278
-
279
- ## Retryable Errors Pattern
280
-
281
- For errors that may be transient, add a `retryable` property:
282
-
283
- ```typescript
284
- export class ServiceUnavailableError extends Schema.TaggedError<ServiceUnavailableError>()(
285
- "ServiceUnavailableError",
286
- {
287
- message: Schema.String,
288
- cause: Schema.optional(Schema.String),
289
- retryable: Schema.optionalWith(Schema.Boolean, { default: () => true }),
290
- },
291
- HttpApiSchema.annotations({ status: 503 }),
292
- ) {}
293
-
294
- export class RateLimitError extends Schema.TaggedError<RateLimitError>()(
295
- "RateLimitError",
296
- {
297
- message: Schema.String,
298
- retryAfter: Schema.optional(Schema.Number),
299
- retryable: Schema.optionalWith(Schema.Boolean, { default: () => true }),
300
- },
301
- HttpApiSchema.annotations({ status: 429 }),
302
- ) {}
303
-
304
- // Non-retryable error
305
- export class ValidationError extends Schema.TaggedError<ValidationError>()(
306
- "ValidationError",
307
- {
308
- message: Schema.String,
309
- field: Schema.String,
310
- retryable: Schema.optionalWith(Schema.Boolean, { default: () => false }),
311
- },
312
- HttpApiSchema.annotations({ status: 400 }),
313
- ) {}
314
- ```
315
-
316
- ### Retry Based on Error Property
317
-
318
- ```typescript
319
- import { Effect, Schedule } from "effect"
320
-
321
- const withRetry = <A, E extends { retryable?: boolean }, R>(
322
- effect: Effect.Effect<A, E, R>
323
- ): Effect.Effect<A, E, R> =>
324
- effect.pipe(
325
- Effect.retry(
326
- Schedule.exponential("100 millis").pipe(
327
- Schedule.intersect(Schedule.recurs(3)),
328
- Schedule.whileInput((err: E) => err.retryable === true),
329
- )
330
- ),
331
- )
332
-
333
- // Usage
334
- yield* callExternalApi(request).pipe(withRetry)
335
- ```
336
-
337
- ## Error Unions for Activities
338
-
339
- When defining workflow activities, use explicit error unions:
340
-
341
- ```typescript
342
- // Activity error type - union of possible errors
343
- export type GetChannelMembersError =
344
- | DatabaseError
345
- | ChannelNotFoundError
346
-
347
- export class DatabaseError extends Schema.TaggedError<DatabaseError>()(
348
- "DatabaseError",
349
- {
350
- message: Schema.String,
351
- cause: Schema.optional(Schema.String),
352
- retryable: Schema.optionalWith(Schema.Boolean, { default: () => true }),
353
- },
354
- ) {}
355
-
356
- export class ChannelNotFoundError extends Schema.TaggedError<ChannelNotFoundError>()(
357
- "ChannelNotFoundError",
358
- {
359
- channelId: ChannelId,
360
- message: Schema.String,
361
- retryable: Schema.optionalWith(Schema.Boolean, { default: () => false }),
362
- },
363
- ) {}
364
-
365
- // In activity definition
366
- yield* Activity.make({
367
- name: "GetChannelMembers",
368
- success: ChannelMembersResult,
369
- error: Schema.Union(DatabaseError, ChannelNotFoundError),
370
- execute: Effect.gen(function* () {
371
- // ...
372
- }),
373
- })
374
- ```
375
-
376
- ## HTTP Status Codes (Without Generic Errors)
377
-
378
- **Map HTTP status codes at the error level, not by creating generic error classes.** Each explicit error can have its own HTTP status.
379
-
380
- ```typescript
381
- // ✅ CORRECT - Domain errors with HTTP status annotations
382
- export class UserNotFoundError extends Schema.TaggedError<UserNotFoundError>()(
383
- "UserNotFoundError",
384
- { userId: UserId, message: Schema.String },
385
- HttpApiSchema.annotations({ status: 404 }), // Status on specific error
386
- ) {}
387
-
388
- export class ChannelNotFoundError extends Schema.TaggedError<ChannelNotFoundError>()(
389
- "ChannelNotFoundError",
390
- { channelId: ChannelId, message: Schema.String },
391
- HttpApiSchema.annotations({ status: 404 }), // Same status, different error
392
- ) {}
393
-
394
- export class SessionExpiredError extends Schema.TaggedError<SessionExpiredError>()(
395
- "SessionExpiredError",
396
- { sessionId: SessionId, expiredAt: Schema.DateTimeUtc, message: Schema.String },
397
- HttpApiSchema.annotations({ status: 401 }),
398
- ) {}
399
-
400
- export class InvalidCredentialsError extends Schema.TaggedError<InvalidCredentialsError>()(
401
- "InvalidCredentialsError",
402
- { message: Schema.String },
403
- HttpApiSchema.annotations({ status: 401 }), // Same status, different meaning
404
- ) {}
405
- ```
406
-
407
- ```typescript
408
- // ❌ WRONG - Generic HTTP error classes
409
- export class UnauthorizedError extends Schema.TaggedError<UnauthorizedError>()(
410
- "UnauthorizedError",
411
- { message: Schema.String },
412
- HttpApiSchema.annotations({ status: 401 }),
413
- ) {}
414
-
415
- // Then mapping everything to it - loses critical information!
416
- Effect.catchTags({
417
- SessionExpiredError: (err) => Effect.fail(new UnauthorizedError({ message: "Unauthorized" })),
418
- InvalidCredentialsError: (err) => Effect.fail(new UnauthorizedError({ message: "Unauthorized" })),
419
- MissingTokenError: (err) => Effect.fail(new UnauthorizedError({ message: "Unauthorized" })),
420
- })
421
- // Frontend can't distinguish: expired session vs wrong password vs missing token
422
- ```
423
-
424
- ### When Generic Errors Are Acceptable
425
-
426
- Generic errors are only acceptable for **truly unrecoverable internal errors** where:
427
- - The frontend can only show "Something went wrong"
428
- - No user action can fix it
429
- - You're hiding internal details for security
430
-
431
- ```typescript
432
- // Acceptable for unrecoverable errors
433
- export class InternalServerError extends Schema.TaggedError<InternalServerError>()(
434
- "InternalServerError",
435
- { message: Schema.String, requestId: Schema.optional(Schema.String) },
436
- HttpApiSchema.annotations({ status: 500 }),
437
- ) {}
438
-
439
- // Use sparingly - only for truly unexpected errors
440
- Effect.catchAll((unexpectedError) =>
441
- Effect.fail(new InternalServerError({
442
- message: "An unexpected error occurred",
443
- requestId: context.requestId,
444
- }))
445
- )
446
- ```
447
-
448
- ## Error Logging
449
-
450
- Log errors with structured context:
451
-
452
- ```typescript
453
- const processWithLogging = Effect.fn("OrderService.process")(function* (orderId: OrderId) {
454
- return yield* processOrder(orderId).pipe(
455
- Effect.tapError((err) =>
456
- Effect.log("Order processing failed", {
457
- orderId,
458
- errorTag: err._tag,
459
- errorMessage: err.message,
460
- })
461
- ),
462
- )
463
- })
464
- ```