Skip to content

Commit

Permalink
fix(client): improve error links (#4753)
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Dec 21, 2020
1 parent 97e7fc3 commit 5b40e3b
Show file tree
Hide file tree
Showing 21 changed files with 336 additions and 187 deletions.
2 changes: 1 addition & 1 deletion src/docker/docker-compose.yml
Expand Up @@ -46,7 +46,7 @@ services:
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
- MYSQL_ROOT_PASSWORD=my-root-pw
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=tests
- MYSQL_USER=prisma
- MYSQL_PASSWORD=prisma
Expand Down
2 changes: 1 addition & 1 deletion src/packages/cli/src/__tests__/version.test.ts
Expand Up @@ -48,5 +48,5 @@ describe('version', () => {
})

function cleanSnapshot(str: string): string {
return str.replaceAll(/\(at .*/g, '')
return str.replace(/\(at .*/g, '')
}
Expand Up @@ -22,6 +22,8 @@ test('error-link', async () => {
TEST_GITHUB_LINK
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.
`)

Expand Down
Expand Up @@ -28,8 +28,34 @@ test('missing-relation', async () => {
TEST_GITHUB_LINK
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.
`)
// try {
// } catch (e) {
// expect(e).toMatchInlineSnapshot(`

// Invalid \`prisma.post.findMany()\` invocation in
// /client/src/__tests__/integration/errors/missing-relation/test.ts:9:23

// 6 const prisma = new PrismaClient()
// 7
// 8 try {
// → 9 await prisma.post.findMany(
// PANIC in query-engine/core/src/response_ir/internal.rs:348:26
// Application logic invariant error: received null value for field author which may not be null

// This is a non-recoverable error which probably happens when the Prisma Query Engine has a panic.

// TEST_GITHUB_LINK

// 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.

// `)
// }

prisma.$disconnect()
})
Expand Down
2 changes: 2 additions & 0 deletions src/packages/client/src/generation/TSClient/TSClient.ts
Expand Up @@ -31,6 +31,7 @@ export interface TSClientOptions {
sqliteDatasourceOverrides?: DatasourceOverwrite[]
schemaDir: string
outputDir: string
activeProvider: string
}

export class TSClient implements Generatable {
Expand Down Expand Up @@ -65,6 +66,7 @@ export class TSClient implements Generatable {
clientVersion: this.options.clientVersion,
engineVersion: this.options.engineVersion,
datasourceNames: this.options.datasources.map((d) => d.name),
activeProvider: this.options.activeProvider,
}
// used for the __dirname polyfill needed for Next.js
const cwdDirname = path.relative(this.options.projectRoot, outputDir)
Expand Down
5 changes: 5 additions & 0 deletions src/packages/client/src/generation/generateClient.ts
Expand Up @@ -51,6 +51,7 @@ export interface GenerateClientOptions {
copyRuntime?: boolean
engineVersion: string
clientVersion: string
activeProvider: string
}

export interface BuildClientResult {
Expand All @@ -72,6 +73,7 @@ export async function buildClient({
engineVersion,
clientVersion,
projectRoot,
activeProvider,
}: GenerateClientOptions): Promise<BuildClientResult> {
const document = getPrismaClientDMMF(dmmf)

Expand All @@ -92,6 +94,7 @@ export async function buildClient({
clientVersion,
engineVersion,
projectRoot: projectRoot!,
activeProvider,
})

const fileMap = {
Expand Down Expand Up @@ -143,6 +146,7 @@ export async function generateClient({
copyRuntime,
clientVersion,
engineVersion,
activeProvider,
}: GenerateClientOptions): Promise<BuildClientResult | undefined> {
const useDotPrisma = testMode ? !runtimePath : !generator?.isCustomOutput

Expand Down Expand Up @@ -171,6 +175,7 @@ export async function generateClient({
clientVersion,
engineVersion,
projectRoot,
activeProvider,
})

const denylistsErrors = validateDmmfAgainstDenylists(prismaClientDmmf)
Expand Down
1 change: 1 addition & 0 deletions src/packages/client/src/generator.ts
Expand Up @@ -39,6 +39,7 @@ generatorHandler({
engineVersion: options.version,
clientVersion,
transpile: true,
activeProvider: options.datasources[0].activeProvider,
})
},
})
Expand Down
4 changes: 3 additions & 1 deletion src/packages/client/src/runtime/getPrismaClient.ts
Expand Up @@ -209,6 +209,7 @@ export interface GetPrismaClientOptions {
clientVersion?: string
engineVersion?: string
datasourceNames: string[]
activeProvider: string
}

export type Action =
Expand Down Expand Up @@ -372,7 +373,8 @@ export function getPrismaClient(config: GetPrismaClientOptions): any {
flags: [],
clientVersion: config.clientVersion,
enableExperimental: mapPreviewFeatures(this._previewFeatures),
useUds: internal.useUds
useUds: internal.useUds,
activeProvider: config.activeProvider,
}

debug({ clientVersion: config.clientVersion })
Expand Down
1 change: 1 addition & 0 deletions src/packages/client/src/utils/generateInFolder.ts
Expand Up @@ -119,6 +119,7 @@ export async function generateInFolder({
generator: config.generators[0],
clientVersion: 'local',
engineVersion: 'local',
activeProvider: 'sqlite',
})

const time = performance.now() - before
Expand Down
1 change: 1 addition & 0 deletions src/packages/client/src/utils/getTestClient.ts
Expand Up @@ -63,6 +63,7 @@ export async function getTestClient(
schemaDir,
outputDir,
),
activeProvider: config.datasources[0].activeProvider,
}

return getPrismaClient(options)
Expand Down
34 changes: 31 additions & 3 deletions src/packages/engine-core/src/Engine.ts
Expand Up @@ -7,6 +7,8 @@ import {
import { getLogs } from '@prisma/debug'
import { getGithubIssueUrl, link } from './util'
import stripAnsi from 'strip-ansi'
import { ConnectorType } from '@prisma/generator-helper'
import { maskQuery } from './maskQuery'

export interface RequestError {
error: string
Expand Down Expand Up @@ -82,7 +84,7 @@ export class PrismaClientRustError extends Error {
constructor({ clientVersion, log, error }: PrismaClientRustErrorArgs) {
if (log) {
const backtrace = getBacktraceFromLog(log)
super(backtrace)
super(backtrace ?? 'Unkown error')
} else if (error) {
const backtrace = getBacktraceFromRustError(error)
super(backtrace)
Expand Down Expand Up @@ -113,6 +115,9 @@ export class PrismaClientInitializationError extends Error {

export interface ErrorWithLinkInput {
version: string
engineVersion?: string
database?: ConnectorType
query: string
platform?: string
title: string
description?: string
Expand All @@ -123,8 +128,11 @@ export function getErrorMessageWithLink({
platform,
title,
description,
engineVersion,
database,
query,
}: ErrorWithLinkInput) {
const gotLogs = getLogs()
const gotLogs = getLogs(6000 - query.length)
const logs = normalizeLogs(stripAnsi(gotLogs))
const moreInfo = description
? `# Description\n\`\`\`\n${description}\n\`\`\``
Expand All @@ -138,13 +146,31 @@ export function getErrorMessageWithLink({
| 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 })
Expand All @@ -155,6 +181,8 @@ This is a non-recoverable error which probably happens when the Prisma Query Eng
${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.
`
}

Expand Down

0 comments on commit 5b40e3b

Please sign in to comment.