Skip to content

Commit

Permalink
Optimize introspection error reporting. Closes #1530
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Feb 7, 2020
1 parent d6b5945 commit b8a3f93
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 20 deletions.
11 changes: 1 addition & 10 deletions cli/introspection/src/commands/Introspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,6 @@ export class Introspect implements Command {
log(`Wrote ${chalk.underline(path.relative(process.cwd(), schemaPath))}`)
}
} catch (e) {
let sqlDump
if (engine.isRunning) {
try {
sqlDump = await engine.getDatabaseDescription(url)
} catch (e) {
console.error(e)
//
}
}
engine.stop()

console.error(chalk.bold.red(`\nIntrospection failed:`) + chalk.red(` Introspected schema can't be parsed.`))
Expand All @@ -188,7 +179,7 @@ export class Introspect implements Command {
ErrorArea.INTROSPECTION_CLI,
undefined,
introspectionSchema,
sqlDump,
url,
)
}

Expand Down
4 changes: 2 additions & 2 deletions cli/prisma2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"bin": "build/index.js",
"prisma": {
"version": "fd8e0ed8e842814e4d425ba989f0c8a48710389d"
"version": "36b88f31e8d49e22e19d857beac80877164b163b"
},
"devDependencies": {
"@prisma/ci-info": "^2.1.1",
Expand Down Expand Up @@ -81,4 +81,4 @@
"prepublishOnly": "pnpm run download && pnpm run ncc:download && pnpm run install && pnpm run test && pnpm run build",
"pkg": "pkg . -o pkg-build"
}
}
}
17 changes: 13 additions & 4 deletions cli/sdk/src/getGenerators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,15 @@ export async function getGenerators({

let prismaPath: string | undefined = undefined

// overwrite query engine if the version is provided
if (version) {
const downloadParams: DownloadOptions = {
binaries: {
'query-engine': eval(`require('path').join(__dirname, '..')`),
},
binaryTargets: [platform],
showProgress: false,
version: version || 'latest',
version,
skipDownload,
}

Expand Down Expand Up @@ -290,9 +291,17 @@ async function validateGenerators(generators: GeneratorConfig[]) {
for (const generator of generators) {
if (generator.provider === 'photonjs') {
throw new Error(`Oops! Photon has been renamed to Prisma Client. Please make the following adjustments:
1. Rename ${chalk.red('provider = "photonjs"')} to ${chalk.green('provider = "prisma-client-js"')} in your ${chalk.bold('schema.prisma')} file.
2. Replace your ${chalk.bold('package.json')}'s ${chalk.red('@prisma/photon')} dependency to ${chalk.green('@prisma/client')}
3. Replace ${chalk.red('import { Photon } from \'@prisma/photon\'')} with ${chalk.green('import { PrismaClient } from \'@prisma/client\'')} in your code.
1. Rename ${chalk.red('provider = "photonjs"')} to ${chalk.green(
'provider = "prisma-client-js"',
)} in your ${chalk.bold('schema.prisma')} file.
2. Replace your ${chalk.bold('package.json')}'s ${chalk.red(
'@prisma/photon',
)} dependency to ${chalk.green('@prisma/client')}
3. Replace ${chalk.red(
"import { Photon } from '@prisma/photon'",
)} with ${chalk.green(
"import { PrismaClient } from '@prisma/client'",
)} in your code.
4. Run ${chalk.green('prisma2 generate')} again.
`)
}
Expand Down
6 changes: 3 additions & 3 deletions cli/sdk/src/panic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export class RustPanic extends Error {
public rustStack: string
public schemaPath?: string
public area: ErrorArea
public sqlDump?: string
public introspectionUrl?: string
public schema?: string
constructor(
message: string,
Expand All @@ -12,15 +12,15 @@ export class RustPanic extends Error {
area: ErrorArea,
schemaPath?: string,
schema?: string,
sqlDump?: string,
introspectionUrl?: string,
) {
super(message)
this.rustStack = rustStack
this.request = request
this.schemaPath = schemaPath
this.area = area
this.schema = schema
this.sqlDump = sqlDump
this.introspectionUrl = introspectionUrl
}
}

Expand Down
18 changes: 17 additions & 1 deletion cli/sdk/src/sendPanic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import tmp from 'tmp'
import { maskSchema } from './utils/maskSchema'
import { RustPanic, ErrorArea } from './panic'
import { getProxyAgent } from '@prisma/fetch-engine'
import { IntrospectionEngine } from './IntrospectionEngine'

const debug = Debug('sendPanic')
// cleanup the temporary files even when an uncaught exception occurs
Expand All @@ -36,6 +37,21 @@ export async function sendPanic(
maskedSchema = maskSchema(schema)
}

let sqlDump: string | undefined
if (error.area === ErrorArea.INTROSPECTION_CLI && error.introspectionUrl) {
let engine: undefined | IntrospectionEngine
try {
engine = new IntrospectionEngine()
sqlDump = await engine.getDatabaseDescription(error.introspectionUrl)
engine.stop()
} catch (e) {
if (engine && engine.isRunning) {
engine.stop()
}
debug(e)
}
}

const signedUrl = await createErrorReport({
area: error.area,
kind: ErrorKind.RUST_PANIC,
Expand All @@ -49,7 +65,7 @@ export async function sendPanic(
liftRequest: JSON.stringify(error.request),
schemaFile: maskedSchema,
fingerprint: getFid() || undefined,
sqlDump: error.sqlDump,
sqlDump,
})

if (error.schemaPath) {
Expand Down

0 comments on commit b8a3f93

Please sign in to comment.