-
Notifications
You must be signed in to change notification settings - Fork 3.6k
fix(tables): surface real error causes on cell-execution failures (diagnostics) #4868
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
Changes from all commits
91f00bd
8812154
e0882cd
67ceef4
6dfbea8
332223b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,60 @@ export function getPostgresConstraintName(error: unknown): string | undefined { | |
| return readPgErrorField(error, 'constraint_name') ?? readPgErrorField(error, 'constraint') | ||
| } | ||
|
|
||
| export interface DescribedError { | ||
| name: string | ||
| message: string | ||
| code?: string | ||
| errno?: string | ||
| syscall?: string | ||
| /** `"Name: message"` per link in the `.cause` chain, outermost first. Present only when the chain has more than one link. */ | ||
| causeChain?: string[] | ||
| } | ||
|
|
||
| /** | ||
| * Always-on diagnostic view of an error and its `.cause` chain. | ||
| * | ||
| * Reports the fields of the DEEPEST `.cause` link, because a wrapped driver | ||
| * error (e.g. Drizzle's `"Failed query: ..."` wrapping an `ECONNRESET`) carries | ||
| * the real reason there, not on the outer wrapper. Always returns a populated | ||
| * object — including for non-`Error` throws and unclassified errors like | ||
| * `AbortError`. Cycle-safe and depth-bounded. | ||
| * | ||
| * Loggers do not serialize the non-enumerable `Error.prototype.cause`, so pass | ||
| * the result as an explicit structured field rather than the raw error. | ||
| */ | ||
| export function describeError(error: unknown): DescribedError { | ||
| const chain: Error[] = [] | ||
| const seen = new Set<unknown>() | ||
| let current: unknown = error | ||
| while (current instanceof Error && !seen.has(current) && chain.length < 10) { | ||
| seen.add(current) | ||
| chain.push(current) | ||
| current = current.cause | ||
| } | ||
|
|
||
| if (chain.length === 0) { | ||
| const normalized = toError(error) | ||
| return { name: normalized.name, message: normalized.message } | ||
| } | ||
|
|
||
| const deepest = chain[chain.length - 1] as Error & Record<string, unknown> | ||
| const asString = (value: unknown): string | undefined => | ||
| typeof value === 'string' ? value : undefined | ||
| const code = asString(deepest.code) | ||
| const errno = asString(deepest.errno) | ||
| const syscall = asString(deepest.syscall) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Numeric errno omitted from logsLow Severity
Reviewed by Cursor Bugbot for commit 332223b. Configure here. |
||
|
|
||
| return { | ||
| name: deepest.name, | ||
| message: deepest.message, | ||
| ...(code ? { code } : {}), | ||
| ...(errno ? { errno } : {}), | ||
| ...(syscall ? { syscall } : {}), | ||
| ...(chain.length > 1 ? { causeChain: chain.map((e) => `${e.name}: ${e.message}`) } : {}), | ||
| } | ||
| } | ||
|
|
||
| function readPgErrorField(error: unknown, field: string): string | undefined { | ||
| const seen = new Set<unknown>() | ||
| let current: unknown = error | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.