MCPcopy
hub / github.com/prisma/prisma / runCommand

Method runCommand

packages/migrate/src/SchemaEngineCLI.ts:513–584  ·  view source on GitHub ↗
(request: RPCPayload)

Source from the content-addressed store, hash-verified

511 }
512
513 private async runCommand(request: RPCPayload): Promise<any> {
514 if (process.env.FORCE_PANIC_SCHEMA_ENGINE && request.method !== 'getDatabaseVersion') {
515 request = this.getRPCPayload('debugPanic', undefined)
516 }
517
518 await this.init()
519
520 if (this.child?.killed) {
521 throw new Error(`Can't execute ${JSON.stringify(request)} because Schema engine already exited.`)
522 }
523
524 return new Promise((resolve, reject) => {
525 this.registerCallback(request.id, (response, err) => {
526 if (err) {
527 return reject(err)
528 }
529
530 // can be null, for reset RPC for example
531 if (response.result !== undefined) {
532 resolve(response.result)
533 } else {
534 if (response.error) {
535 debugRpc(response)
536 if (response.error.data?.is_panic) {
537 // TODO(jkomyno): I suspect no panic is ever thrown here
538
539 const message = response.error.data?.error?.message ?? response.error.message
540
541 // explicitly mark the error as a "response error panic" to distinguish it from the other one.
542 // This will allow us to track the frequency of this particular panic in the error reporting system.
543 const stackTrace = `[RESPONSE_ERROR_PANIC]\n${response.error.data?.message ?? ''}`
544
545 reject(
546 // Handle error and displays the interactive dialog to send panic error
547 new RustPanic(message, stackTrace, this.lastRequest, ErrorArea.LIFT_CLI),
548 )
549 } else if (response.error.data?.message) {
550 // Print known error code & message from engine
551 // See known errors at https://github.com/prisma/specs/tree/master/errors#prisma-sdk
552 let message = `${red(relativizePathInPSLError(response.error.data.message))}\n`
553 if (response.error.data?.error_code) {
554 message = red(`${response.error.data.error_code}\n\n`) + message
555 reject(new EngineError(message, response.error.data.error_code))
556 } else {
557 reject(new Error(message))
558 }
559 } else {
560 reject(
561 new Error(
562 `${red('Error in RPC')}\n Request: ${JSON.stringify(request, null, 2)}\nResponse: ${JSON.stringify(
563 response,
564 null,
565 2,
566 )}\n${response.error.message}\n`,
567 ),
568 )
569 }
570 } else {

Callers 15

applyMigrationsMethod · 0.95
createDatabaseMethod · 0.95
createMigrationMethod · 0.95
dbExecuteMethod · 0.95
debugPanicMethod · 0.95
devDiagnosticMethod · 0.95
evaluateDataLossMethod · 0.95
getDatabaseVersionMethod · 0.95
introspectMethod · 0.95

Calls 6

getRPCPayloadMethod · 0.95
initMethod · 0.95
registerCallbackMethod · 0.95
relativizePathInPSLErrorFunction · 0.90
writeMethod · 0.65
resolveFunction · 0.50

Tested by

no test coverage detected