-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
401 additions
and
338 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
File renamed without changes.
This file contains 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
14 changes: 14 additions & 0 deletions
14
src/packages/engine-core/src/common/errors/PrismaClientInitializationError.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export class PrismaClientInitializationError extends Error { | ||
clientVersion: string | ||
errorCode?: string | ||
|
||
constructor(message: string, clientVersion: string, errorCode?: string) { | ||
super(message) | ||
this.clientVersion = clientVersion | ||
this.errorCode = errorCode | ||
Error.captureStackTrace(PrismaClientInitializationError) | ||
} | ||
get [Symbol.toStringTag]() { | ||
return 'PrismaClientInitializationError' | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/packages/engine-core/src/common/errors/PrismaClientKnownRequestError.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export class PrismaClientKnownRequestError extends Error { | ||
code: string | ||
meta?: object | ||
clientVersion: string | ||
|
||
constructor( | ||
message: string, | ||
code: string, | ||
clientVersion: string, | ||
meta?: any, | ||
) { | ||
super(message) | ||
|
||
this.code = code | ||
this.clientVersion = clientVersion | ||
this.meta = meta | ||
} | ||
get [Symbol.toStringTag]() { | ||
return 'PrismaClientKnownRequestError' | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/packages/engine-core/src/common/errors/PrismaClientRustError.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { getBacktraceFromLog, getBacktraceFromRustError } from './utils/log' | ||
import { PrismaClientRustErrorArgs } from './types/PrismaClientRustErrorArgs' | ||
|
||
/** | ||
* A generic Prisma Client Rust error. | ||
* This error is being exposed via the `prisma.$on('error')` interface | ||
*/ | ||
export class PrismaClientRustError extends Error { | ||
clientVersion: string | ||
|
||
constructor({ clientVersion, log, error }: PrismaClientRustErrorArgs) { | ||
if (log) { | ||
const backtrace = getBacktraceFromLog(log) | ||
super(backtrace ?? 'Unkown error') | ||
} else if (error) { | ||
const backtrace = getBacktraceFromRustError(error) | ||
super(backtrace) | ||
} else { | ||
// this should never happen | ||
super(`Unknown error`) | ||
} | ||
|
||
this.clientVersion = clientVersion | ||
} | ||
get [Symbol.toStringTag]() { | ||
return 'PrismaClientRustPanicError' | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/packages/engine-core/src/common/errors/PrismaClientRustPanicError.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export class PrismaClientRustPanicError extends Error { | ||
clientVersion: string | ||
|
||
constructor(message: string, clientVersion: string) { | ||
super(message) | ||
|
||
this.clientVersion = clientVersion | ||
} | ||
get [Symbol.toStringTag]() { | ||
return 'PrismaClientRustPanicError' | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/packages/engine-core/src/common/errors/PrismaClientUnknownRequestError.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export class PrismaClientUnknownRequestError extends Error { | ||
clientVersion: string | ||
|
||
constructor(message: string, clientVersion: string) { | ||
super(message) | ||
|
||
this.clientVersion = clientVersion | ||
} | ||
get [Symbol.toStringTag]() { | ||
return 'PrismaClientUnknownRequestError' | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/packages/engine-core/src/common/errors/types/ErrorWithLinkInput.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { ConnectorType } from '@prisma/generator-helper' | ||
|
||
export interface ErrorWithLinkInput { | ||
version: string | ||
engineVersion?: string | ||
database?: ConnectorType | ||
query?: string | ||
platform?: string | ||
title: string | ||
description?: string | ||
} |
7 changes: 7 additions & 0 deletions
7
src/packages/engine-core/src/common/errors/types/PrismaClientRustErrorArgs.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { RustLog, RustError } from '../utils/log' | ||
|
||
export type PrismaClientRustErrorArgs = { | ||
clientVersion: string | ||
log?: RustLog | ||
error?: RustError | ||
} |
9 changes: 9 additions & 0 deletions
9
src/packages/engine-core/src/common/errors/types/RequestError.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export interface RequestError { | ||
error: string | ||
user_facing_error: { | ||
is_panic: boolean | ||
message: string | ||
meta?: object | ||
error_code?: string | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
src/packages/engine-core/src/common/errors/utils/getErrorMessageWithLink.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { getLogs } from '@prisma/debug' | ||
import { getGithubIssueUrl, link } from '../../utils/util' | ||
import stripAnsi from 'strip-ansi' | ||
import { maskQuery } from './maskQuery' | ||
import { normalizeLogs } from './normalizeLogs' | ||
import { ErrorWithLinkInput } from '../types/ErrorWithLinkInput' | ||
|
||
export function getErrorMessageWithLink({ | ||
version, | ||
platform, | ||
title, | ||
description, | ||
engineVersion, | ||
database, | ||
query, | ||
}: ErrorWithLinkInput) { | ||
const gotLogs = getLogs(6000 - (query?.length ?? 0)) | ||
const logs = normalizeLogs(stripAnsi(gotLogs)) | ||
const moreInfo = description | ||
? `# Description\n\`\`\`\n${description}\n\`\`\`` | ||
: '' | ||
const body = stripAnsi( | ||
`Hi Prisma Team! My Prisma Client just crashed. This is the report: | ||
## Versions | ||
| Name | Version | | ||
|-----------------|--------------------| | ||
| Node | ${process.version?.padEnd(19)}| | ||
| OS | ${platform?.padEnd(19)}| | ||
| Prisma Client | ${version?.padEnd(19)}| | ||
| Query Engine | ${engineVersion?.padEnd(19)}| | ||
| Database | ${database?.padEnd(19)}| | ||
${moreInfo} | ||
## Query | ||
\`\`\` | ||
${query ? maskQuery(query) : ''} | ||
\`\`\` | ||
## Logs | ||
\`\`\` | ||
${logs} | ||
\`\`\` | ||
## Client Snippet | ||
\`\`\`ts | ||
// PLEASE FILL YOUR CODE SNIPPET HERE | ||
\`\`\` | ||
## Schema | ||
\`\`\`prisma | ||
// PLEASE ADD YOUR SCHEMA HERE IF POSSIBLE | ||
\`\`\` | ||
`, | ||
) | ||
|
||
const url = getGithubIssueUrl({ title, body }) | ||
return `${title} | ||
This is a non-recoverable error which probably happens when the Prisma Query Engine has a panic. | ||
${link(url)} | ||
If you want the Prisma team to look into it, please open the link above 🙏 | ||
To increase the chance of success, please post your schema and a snippet of | ||
how you used Prisma Client in the issue. | ||
` | ||
} |
File renamed without changes.
File renamed without changes.
17 changes: 17 additions & 0 deletions
17
src/packages/engine-core/src/common/errors/utils/normalizeLogs.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Removes the leading timestamps (from docker) and trailing ms (from debug) | ||
* @param logs logs to normalize | ||
*/ | ||
export function normalizeLogs(logs: string): string { | ||
return logs | ||
.split('\n') | ||
.map((l) => { | ||
return l | ||
.replace( | ||
/^\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z)\s*/, | ||
'', | ||
) | ||
.replace(/\+\d+\s*ms$/, '') | ||
}) | ||
.join('\n') | ||
} |
Oops, something went wrong.