Repository navigation
fix(effect-runtime): surface bounded underlying handler error for local operability #9434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alaleiwang
wants to merge
1
commit into
loopx-project:main
Choose a base branch
from
alaleiwang:feat/qualified-node-sqlite
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,137 +1,140 @@ | ||
| export const EFFECT_RUNTIME_ERROR_KINDS = [ | ||
| "request_rejected", | ||
| "conflict", | ||
| "io_transient", | ||
| "io_permanent", | ||
| "lock_timeout", | ||
| "internal_failure", | ||
| ] as const; | ||
|
|
||
| export type EffectRuntimeErrorKind = | ||
| (typeof EFFECT_RUNTIME_ERROR_KINDS)[number]; | ||
|
|
||
| export interface EffectRuntimeErrorPayload { | ||
| kind: EffectRuntimeErrorKind; | ||
| code: string; | ||
| message: string; | ||
| details?: string[]; | ||
| } | ||
|
|
||
| abstract class EffectRuntimeBoundaryError extends Error { | ||
| abstract readonly kind: EffectRuntimeErrorKind; | ||
| readonly code: string; | ||
|
|
||
| constructor(message: string, code: string) { | ||
| super(message); | ||
| this.name = new.target.name; | ||
| this.code = code; | ||
| } | ||
| } | ||
|
|
||
| export class EffectRuntimeRequestError extends EffectRuntimeBoundaryError { | ||
| readonly kind = "request_rejected" as const; | ||
| readonly details?: readonly string[]; | ||
|
|
||
| constructor(message: string, code = "invalid_request", details?: readonly string[]) { | ||
| super(message, code); | ||
| this.details = details; | ||
| } | ||
| } | ||
|
|
||
| export class EffectRuntimeConflictError extends EffectRuntimeBoundaryError { | ||
| readonly kind = "conflict" as const; | ||
|
|
||
| constructor(message: string, code = "state_conflict") { | ||
| super(message, code); | ||
| } | ||
| } | ||
|
|
||
| export class EffectRuntimeLockTimeoutError extends EffectRuntimeBoundaryError { | ||
| readonly kind = "lock_timeout" as const; | ||
|
|
||
| constructor(message = "Effect runtime mutation lock timed out") { | ||
| super(message, "mutation_lock_timeout"); | ||
| } | ||
| } | ||
|
|
||
| const TRANSIENT_IO_CODES: Readonly<Record<string, string>> = { | ||
| EAGAIN: "io_temporarily_unavailable", | ||
| EBUSY: "io_busy", | ||
| EMFILE: "io_process_descriptor_limit", | ||
| ENFILE: "io_system_descriptor_limit", | ||
| ETIMEDOUT: "io_timed_out", | ||
| }; | ||
|
|
||
| const PERMANENT_IO_CODES: Readonly<Record<string, string>> = { | ||
| EACCES: "io_permission_denied", | ||
| EDQUOT: "io_quota_exhausted", | ||
| EINVAL: "io_invalid_operation", | ||
| EISDIR: "io_is_directory", | ||
| ENAMETOOLONG: "io_name_too_long", | ||
| ENOENT: "io_not_found", | ||
| ENOSPC: "io_space_exhausted", | ||
| ENOTDIR: "io_not_directory", | ||
| EPERM: "io_permission_denied", | ||
| EROFS: "io_read_only", | ||
| }; | ||
|
|
||
| function boundedMessage(value: string, fallback: string): string { | ||
| const singleLine = value.replace(/\s+/g, " ").trim(); | ||
| return (singleLine || fallback).slice(0, 240); | ||
| } | ||
|
|
||
| function nodeErrorCode(error: unknown): string | null { | ||
| if (typeof error !== "object" || error === null) return null; | ||
| const code = (error as {code?: unknown}).code; | ||
| return typeof code === "string" ? code : null; | ||
| } | ||
|
|
||
| function isNodeSystemError(error: unknown): boolean { | ||
| return typeof error === "object" && | ||
| error !== null && | ||
| typeof (error as {syscall?: unknown}).syscall === "string"; | ||
| } | ||
|
|
||
| export function effectRuntimeErrorPayload( | ||
| error: unknown, | ||
| ): EffectRuntimeErrorPayload { | ||
| if (error instanceof EffectRuntimeBoundaryError) { | ||
| const payload: EffectRuntimeErrorPayload = { | ||
| kind: error.kind, | ||
| code: error.code, | ||
| message: boundedMessage(error.message, "Effect runtime request failed"), | ||
| }; | ||
| if (error instanceof EffectRuntimeRequestError && error.details?.length) { | ||
| payload.details = error.details.slice(0, 128).map(detail => boundedMessage(detail, "Request validation failed")); | ||
| if (error.details.length > 128) payload.details[127] = `${error.details.length - 127} additional validation details omitted`; | ||
| } | ||
| return payload; | ||
| } | ||
| const ioCode = nodeErrorCode(error); | ||
| if (ioCode && TRANSIENT_IO_CODES[ioCode]) { | ||
| return { | ||
| kind: "io_transient", | ||
| code: TRANSIENT_IO_CODES[ioCode], | ||
| message: "Effect runtime filesystem operation is temporarily unavailable", | ||
| }; | ||
| } | ||
| if (ioCode && PERMANENT_IO_CODES[ioCode]) { | ||
| return { | ||
| kind: "io_permanent", | ||
| code: PERMANENT_IO_CODES[ioCode], | ||
| message: "Effect runtime filesystem operation failed", | ||
| }; | ||
| } | ||
| if (ioCode && isNodeSystemError(error)) { | ||
| return { | ||
| kind: "io_permanent", | ||
| code: "io_failure", | ||
| message: "Effect runtime filesystem operation failed", | ||
| }; | ||
| } | ||
| return { | ||
| kind: "internal_failure", | ||
| code: "unexpected_handler_error", | ||
| message: "Effect runtime handler failed unexpectedly", | ||
| }; | ||
| } | ||
| export const EFFECT_RUNTIME_ERROR_KINDS = [ | ||
| "request_rejected", | ||
| "conflict", | ||
| "io_transient", | ||
| "io_permanent", | ||
| "lock_timeout", | ||
| "internal_failure", | ||
| ] as const; | ||
|
|
||
| export type EffectRuntimeErrorKind = | ||
| (typeof EFFECT_RUNTIME_ERROR_KINDS)[number]; | ||
|
|
||
| export interface EffectRuntimeErrorPayload { | ||
| kind: EffectRuntimeErrorKind; | ||
| code: string; | ||
| message: string; | ||
| details?: string[]; | ||
| } | ||
|
|
||
| abstract class EffectRuntimeBoundaryError extends Error { | ||
| abstract readonly kind: EffectRuntimeErrorKind; | ||
| readonly code: string; | ||
|
|
||
| constructor(message: string, code: string) { | ||
| super(message); | ||
| this.name = new.target.name; | ||
| this.code = code; | ||
| } | ||
| } | ||
|
|
||
| export class EffectRuntimeRequestError extends EffectRuntimeBoundaryError { | ||
| readonly kind = "request_rejected" as const; | ||
| readonly details?: readonly string[]; | ||
|
|
||
| constructor(message: string, code = "invalid_request", details?: readonly string[]) { | ||
| super(message, code); | ||
| this.details = details; | ||
| } | ||
| } | ||
|
|
||
| export class EffectRuntimeConflictError extends EffectRuntimeBoundaryError { | ||
| readonly kind = "conflict" as const; | ||
|
|
||
| constructor(message: string, code = "state_conflict") { | ||
| super(message, code); | ||
| } | ||
| } | ||
|
|
||
| export class EffectRuntimeLockTimeoutError extends EffectRuntimeBoundaryError { | ||
| readonly kind = "lock_timeout" as const; | ||
|
|
||
| constructor(message = "Effect runtime mutation lock timed out") { | ||
| super(message, "mutation_lock_timeout"); | ||
| } | ||
| } | ||
|
|
||
| const TRANSIENT_IO_CODES: Readonly<Record<string, string>> = { | ||
| EAGAIN: "io_temporarily_unavailable", | ||
| EBUSY: "io_busy", | ||
| EMFILE: "io_process_descriptor_limit", | ||
| ENFILE: "io_system_descriptor_limit", | ||
| ETIMEDOUT: "io_timed_out", | ||
| }; | ||
|
|
||
| const PERMANENT_IO_CODES: Readonly<Record<string, string>> = { | ||
| EACCES: "io_permission_denied", | ||
| EDQUOT: "io_quota_exhausted", | ||
| EINVAL: "io_invalid_operation", | ||
| EISDIR: "io_is_directory", | ||
| ENAMETOOLONG: "io_name_too_long", | ||
| ENOENT: "io_not_found", | ||
| ENOSPC: "io_space_exhausted", | ||
| ENOTDIR: "io_not_directory", | ||
| EPERM: "io_permission_denied", | ||
| EROFS: "io_read_only", | ||
| }; | ||
|
|
||
| function boundedMessage(value: string, fallback: string): string { | ||
| const singleLine = value.replace(/\s+/g, " ").trim(); | ||
| return (singleLine || fallback).slice(0, 240); | ||
| } | ||
|
|
||
| function nodeErrorCode(error: unknown): string | null { | ||
| if (typeof error !== "object" || error === null) return null; | ||
| const code = (error as {code?: unknown}).code; | ||
| return typeof code === "string" ? code : null; | ||
| } | ||
|
|
||
| function isNodeSystemError(error: unknown): boolean { | ||
| return typeof error === "object" && | ||
| error !== null && | ||
| typeof (error as {syscall?: unknown}).syscall === "string"; | ||
| } | ||
|
|
||
| export function effectRuntimeErrorPayload( | ||
| error: unknown, | ||
| ): EffectRuntimeErrorPayload { | ||
| if (error instanceof EffectRuntimeBoundaryError) { | ||
| const payload: EffectRuntimeErrorPayload = { | ||
| kind: error.kind, | ||
| code: error.code, | ||
| message: boundedMessage(error.message, "Effect runtime request failed"), | ||
| }; | ||
| if (error instanceof EffectRuntimeRequestError && error.details?.length) { | ||
| payload.details = error.details.slice(0, 128).map(detail => boundedMessage(detail, "Request validation failed")); | ||
| if (error.details.length > 128) payload.details[127] = `${error.details.length - 127} additional validation details omitted`; | ||
| } | ||
| return payload; | ||
| } | ||
| const ioCode = nodeErrorCode(error); | ||
| if (ioCode && TRANSIENT_IO_CODES[ioCode]) { | ||
| return { | ||
| kind: "io_transient", | ||
| code: TRANSIENT_IO_CODES[ioCode], | ||
| message: "Effect runtime filesystem operation is temporarily unavailable", | ||
| }; | ||
| } | ||
| if (ioCode && PERMANENT_IO_CODES[ioCode]) { | ||
| return { | ||
| kind: "io_permanent", | ||
| code: PERMANENT_IO_CODES[ioCode], | ||
| message: "Effect runtime filesystem operation failed", | ||
| }; | ||
| } | ||
| if (ioCode && isNodeSystemError(error)) { | ||
| return { | ||
| kind: "io_permanent", | ||
| code: "io_failure", | ||
| message: "Effect runtime filesystem operation failed", | ||
| }; | ||
| } | ||
| return { | ||
| kind: "internal_failure", | ||
| code: "unexpected_handler_error", | ||
| message: boundedMessage( | ||
| `Effect runtime handler failed unexpectedly: ${(error as any)?.message || String(error)}`, | ||
| "Effect runtime handler failed unexpectedly", | ||
| ), | ||
| }; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P2] 未知异常携带无法安全转为字符串的值,通用 handler 已进入 error serializer。 当前 fallback 在格式化任意异常时自身抛出 TypeError,exchange 未产出原 request ID 的 typed response。既有 Node 分类测试及 Python 真 socket journal 回读也各新增一项失败。 在 SQLite 资格 owner 构造可公开的稳定诊断,保留通用的不可抛出 fallback。恢复 committed 差异的原 LF 行结尾,并复跑两个回归入口。