MCPcopy
hub / github.com/prisma/prisma / validate

Function validate

packages/internals/src/engine-commands/validate.ts:46–117  ·  view source on GitHub ↗
(options: ValidateOptions)

Source from the content-addressed store, hash-verified

44 * Wasm'd version of `validate`.
45 */
46export function validate(options: ValidateOptions): void {
47 const debugErrorType = createDebugErrorType(debug, 'validateWasm')
48 debug(`Using validate Wasm`)
49
50 const validateEither = pipe(
51 E.tryCatch(
52 () => {
53 /**
54 * Note: `validate` was introduced as a substitute of `getDMMF` to validate schemas the
55 * same way `getDMMF` did, but without the expensive DMMF document computation, so we
56 * keep using `FORCE_PANIC_GET_DMMF` to avoid breaking changes in env vars.
57 */
58 if (process.env.FORCE_PANIC_GET_DMMF) {
59 debug('Triggering a Rust panic...')
60 prismaSchemaWasm.debug_panic()
61 }
62
63 const params = JSON.stringify({
64 prismaSchema: options.schemas,
65 noColor: Boolean(process.env.NO_COLOR),
66 })
67 prismaSchemaWasm.validate(params)
68 },
69 (e) =>
70 ({
71 type: 'wasm-error' as const,
72 reason: '(validate wasm)',
73 error: e as Error | WasmPanic,
74 }) as const,
75 ),
76 )
77
78 if (E.isRight(validateEither)) {
79 return
80 }
81
82 /**
83 * Check which error to throw.
84 */
85 const error = match(validateEither.left)
86 .with({ type: 'wasm-error' }, (e) => {
87 debugErrorType(e)
88
89 console.error('') // empty line for better readability
90
91 /**
92 * Capture and propagate possible Wasm panics.
93 */
94 if (isWasmPanic(e.error)) {
95 const { message, stack } = getWasmError(e.error)
96 debug(`Error validating schema: ${message}`)
97 debug(stack)
98
99 const panic = new RustPanic(
100 /* message */ message,
101 /* rustStack */ stack,
102 /* request */ '@prisma/prisma-schema-wasm validate',
103 ErrorArea.FMT_CLI,

Callers 4

parseMethod · 0.90
parseMethod · 0.90
parseMethod · 0.90
validate.test.tsFile · 0.85

Calls 8

createDebugErrorTypeFunction · 0.90
isWasmPanicFunction · 0.90
getWasmErrorFunction · 0.90
parseQueryEngineErrorFunction · 0.90
debugFunction · 0.85
errorMethod · 0.80
withMethod · 0.65
pipeFunction · 0.50

Tested by

no test coverage detected