prisma: Error `prisma generate` on huge schema (100+ tables)

Bug description

Prisma throwing error on very large schema:

RangeError: Invalid string length
    at PassThrough.stream.getBufferedValue (/Users/r/Documents/wms-pos/node_modules/prisma/build/index.js:2913:25)
    at rejectPromise (/Users/r/Documents/wms-pos/node_modules/prisma/build/index.js:2953:40)
    at PassThrough.<anonymous> (/Users/r/Documents/wms-pos/node_modules/prisma/build/index.js:2967:11)
    at PassThrough.emit (node:events:406:35)
    at PassThrough.emit (node:domain:470:12)
    at addChunk (node:internal/streams/readable:312:12)
    at readableAddChunk (node:internal/streams/readable:283:11)
    at PassThrough.Readable.push (node:internal/streams/readable:226:10)
    at node:internal/streams/transform:192:12
    at PassThrough._transform (node:internal/streams/passthrough:46:3)

How to reproduce

  1. Create blank prisma project
  2. Use provided prisma schema
  3. See the error

Expected behavior

npx prisma generate run succesfully

Prisma information

schema.prisma.zip

Environment & setup

  • OS: macOS
  • Database: PostgreSQL
  • Node.js version: v.16.5.0

Prisma Version

prisma               : 2.28.0
@prisma/client       : 2.28.0
Current platform     : darwin-arm64
Query Engine         : query-engine 89facabd0366f63911d089156a7a70125bfbcd27 (at ../../node_modules/prisma/node_modules/@prisma/engines/query-engine-darwin-arm64)
Migration Engine     : migration-engine-cli 89facabd0366f63911d089156a7a70125bfbcd27 (at ../../node_modules/prisma/node_modules/@prisma/engines/migration-engine-darwin-arm64)
Introspection Engine : introspection-core 89facabd0366f63911d089156a7a70125bfbcd27 (at ../../node_modules/prisma/node_modules/@prisma/engines/introspection-engine-darwin-arm64)
Format Binary        : prisma-fmt 89facabd0366f63911d089156a7a70125bfbcd27 (at ../../node_modules/prisma/node_modules/@prisma/engines/prisma-fmt-darwin-arm64)
Default Engines Hash : 89facabd0366f63911d089156a7a70125bfbcd27
Studio               : 0.417.0

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 3
  • Comments: 15 (11 by maintainers)

Most upvoted comments

@janpio update, I just re-run newly installed prisma with the same schema… now it returns shorter error:

image

I think I’m also hitting this issue. @janpio I am emailing over our schema now and will link this comment in the email

Here are the errors I’m seeing

env DEBUG="*" npx prisma generate
  prisma:engines binaries to download libquery-engine, migration-engine, introspection-engine, prisma-fmt +0ms
  prisma:loadEnv project root found at /Users/tnrich/Sites/prisma-trial/package.json +0ms
  prisma:tryLoadEnv Environment variables loaded from /Users/tnrich/Sites/prisma-trial/.env +0ms
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
  prisma:getConfig Using CLI Query Engine (Node-API Library) at: /Users/tnrich/Sites/prisma-trial/node_modules/prisma/libquery_engine-darwin-arm64.dylib.node +0ms
  prisma:getDMMF Using CLI Query Engine (Node-API) at: /Users/tnrich/Sites/prisma-trial/node_modules/prisma/libquery_engine-darwin-arm64.dylib.node +0ms
Error: SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at getDmmfNodeAPI (/Users/tnrich/Sites/prisma-trial/node_modules/prisma/build/index.js:36850:28)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async getDMMF (/Users/tnrich/Sites/prisma-trial/node_modules/prisma/build/index.js:36829:17)
    at async getGenerators (/Users/tnrich/Sites/prisma-trial/node_modules/prisma/build/index.js:39798:20)
    at async Object.parse (/Users/tnrich/Sites/prisma-trial/node_modules/prisma/build/index.js:107978:20)
    at async main (/Users/tnrich/Sites/prisma-trial/node_modules/prisma/build/index.js:109506:18)



//after setting PRISMA_CLI_QUERY_ENGINE_TYPE=binary in .env
tnrich@thomass-mbp prisma-trial % env DEBUG="*" npx prisma generate
  prisma:engines binaries to download libquery-engine, migration-engine, introspection-engine, prisma-fmt +0ms
  prisma:loadEnv project root found at /Users/tnrich/Sites/prisma-trial/package.json +0ms
  prisma:tryLoadEnv Environment variables loaded from /Users/tnrich/Sites/prisma-trial/.env +0ms
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
  prisma:download file /Users/tnrich/Sites/prisma-trial/node_modules/prisma/query-engine-darwin-arm64 does not exist and must be downloaded +0ms
  prisma:download Downloading https://binaries.prisma.sh/all_commits/1a2506facaf1a4727b7c26850735e88ec779dee9/darwin-arm64/query-engine.gz to /Users/tnrich/Sites/prisma-trial/node_modules/prisma/query-engine-darwin-arm64 +0ms
  prisma:getConfig Using CLI Query Engine (Binary) at: /Users/tnrich/Sites/prisma-trial/node_modules/prisma/query-engine-darwin-arm64 +0ms
  prisma:getDMMF Using CLI Query Engine (Binary) at: /Users/tnrich/Sites/prisma-trial/node_modules/prisma/query-engine-darwin-arm64 +0ms
  prisma:cli RangeError: Invalid string length
  prisma:cli     at Array.join (<anonymous>)
  prisma:cli     at PassThrough.stream5.getBufferedValue (/Users/tnrich/Sites/prisma-trial/node_modules/prisma/build/index.js:3878:66)
  prisma:cli     at rejectPromise (/Users/tnrich/Sites/prisma-trial/node_modules/prisma/build/index.js:3913:42)
  prisma:cli     at PassThrough.<anonymous> (/Users/tnrich/Sites/prisma-trial/node_modules/prisma/build/index.js:3927:13)
  prisma:cli     at PassThrough.emit (node:events:402:35)
  prisma:cli     at addChunk (node:internal/streams/readable:315:12)
  prisma:cli     at readableAddChunk (node:internal/streams/readable:285:11)
  prisma:cli     at PassThrough.Readable.push (node:internal/streams/readable:228:10)
  prisma:cli     at node:internal/streams/transform:192:12
  prisma:cli     at PassThrough._transform (node:internal/streams/passthrough:46:3) +0ms

Another very interesting thing happens if you switch back to the binary engine file:

C:\Users\Jan\Documents\throwaway\9417>set PRISMA_CLI_QUERY_ENGINE_TYPE=binary 

C:\Users\Jan\Documents\throwaway\9417>npx prisma generate
  prisma:loadEnv project root found at C:\Users\Jan\Documents\throwaway\9417\package.json +0ms
  prisma:tryLoadEnv Environment variables loaded from C:\Users\Jan\Documents\throwaway\9417\.env +0ms
Environment variables loaded from .env
  prisma:engines binaries to download query-engine, migration-engine, introspection-engine, prisma-fmt +0ms
  prisma:download file C:\Users\Jan\Documents\throwaway\9417\node_modules\@prisma\engines\query-engine-windows.exe does not exist and must be downloaded +0ms
  prisma:download Downloading https://binaries.prisma.sh/all_commits/c22652b7e418506fab23052d569b85d3aec4883f/windows/query-engine.exe.gz to C:\Users\Jan\Documents\throwaway\9417\node_modules\@prisma\engines\query-engine-windows.exe +533ms
Prisma schema loaded from prisma\schema.prisma
  prisma:download copying C:\Users\Jan\Documents\throwaway\9417\node_modules\.cache\prisma\master\c22652b7e418506fab23052d569b85d3aec4883f\windows\query-engine to C:\Users\Jan\Documents\throwaway\9417\node_modules\prisma\query-engine-windows.exe +0ms
  prisma:getConfig Using CLI Query Engine (Binary) at: C:\Users\Jan\Documents\throwaway\9417\node_modules\prisma\query-engine-windows.exe +0ms
  prisma:getDMMF Using CLI Query Engine (Binary) at: C:\Users\Jan\Documents\throwaway\9417\node_modules\prisma\query-engine-windows.exe +0ms
  prisma:getDMMF getDMMF failed Error: Command failed with exit code 101: C:\Users\Jan\Documents\throwaway\9417\node_modules\prisma\query-engine-windows.exe --enable-raw-queries cli dmmf
thread 'main' panicked at 'failed printing to stdout: Insufficient system resources exist to complete the requested service. (os error 1450)', library\std\src\io\stdio.rs:1193:9
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
    at makeError (C:\Users\Jan\Documents\throwaway\9417\node_modules\prisma\build\index.js:2565:15)
    at handlePromise (C:\Users\Jan\Documents\throwaway\9417\node_modules\prisma\build\index.js:3255:31)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async getDmmfBinary (C:\Users\Jan\Documents\throwaway\9417\node_modules\prisma\build\index.js:32610:16)
    at async getDMMF5 (C:\Users\Jan\Documents\throwaway\9417\node_modules\prisma\build\index.js:32566:14)
    at async Object.getGenerators (C:\Users\Jan\Documents\throwaway\9417\node_modules\prisma\build\index.js:35010:18)
    at async _Generate.parse (C:\Users\Jan\Documents\throwaway\9417\node_modules\prisma\build\index.js:67509:22)
    at async main (C:\Users\Jan\Documents\throwaway\9417\node_modules\prisma\build\index.js:112748:18) {
  shortMessage: 'Command failed with exit code 101: C:\\Users\\Jan\\Documents\\throwaway\\9417\\node_modules\\prisma\\query-engine-windows.exe --enable-raw-queries cli dmmf',
  command: 'C:\\Users\\Jan\\Documents\\throwaway\\9417\\node_modules\\prisma\\query-engine-windows.exe --enable-raw-queries cli dmmf',
  escapedCommand: '"C:\\Users\\Jan\\Documents\\throwaway\\9417\\node_modules\\prisma\\query-engine-windows.exe" --enable-raw-queries cli dmmf',
  exitCode: 101,
  signal: undefined,
  signalDescription: undefined,
  stdout: '',
  stderr: "thread 'main' panicked at 'failed printing to stdout: Insufficient system resources exist to complete the requested service. (os error 1450)', library\\std\\src\\io\\stdio.rs:1193:9\n" +
    'stack backtrace:\n' +
    'note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.',
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false
} +30s
Error: Error: Schema parsing
thread 'main' panicked at 'failed printing to stdout: Insufficient system resources exist to complete the requested service. (os error 1450)', library\std\src\io\stdio.rs:1193:9
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
    at getDmmfBinary (C:\Users\Jan\Documents\throwaway\9417\node_modules\prisma\build\index.js:32644:15)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async getDMMF5 (C:\Users\Jan\Documents\throwaway\9417\node_modules\prisma\build\index.js:32566:14)
    at async Object.getGenerators (C:\Users\Jan\Documents\throwaway\9417\node_modules\prisma\build\index.js:35010:18)
    at async _Generate.parse (C:\Users\Jan\Documents\throwaway\9417\node_modules\prisma\build\index.js:67509:22)
    at async main (C:\Users\Jan\Documents\throwaway\9417\node_modules\prisma\build\index.js:112748:18)

C:\Users\Jan\Documents\throwaway\9417>
  stderr: "thread 'main' panicked at 'failed printing to stdout: Insufficient system resources exist to complete the requested service. (os error 1450)', library\\std\\src\\io\\stdio.rs:1193:9\n" +

I could reproduce on 5.1.0, the error changed a bit now.

Error: GetDmmfError: (get-dmmf wasm)
Details: The encoded data was not valid for encoding utf-8
[Context: getDmmf]

Prisma CLI Version : 5.1.0

Note: I had to fix some schema validations, so here is the updated schema file: schema.prisma.zip

DEBUG=* npx prisma generate
  prisma:engines  binaries to download libquery-engine, schema-engine +0ms
  prisma:loadEnv  project root found at /Users/j42/Repros/8525/package.json +0ms
  prisma:tryLoadEnv  Environment variables not found at null +0ms
  prisma:try
[schema.prisma.zip](https://github.com/prisma/prisma/files/12238966/schema.prisma.zip)
LoadEnv  Environment variables loaded from ./prisma/.env +0ms
Environment variables loaded from prisma/.env
Prisma schema loaded from prisma/schema.prisma
  prisma:getConfig  Using getConfig Wasm +0ms
  prisma:getConfig  config data retrieved without errors in getConfig Wasm +93ms
  prisma:getDMMF  Using getDmmf Wasm +0ms
  prisma:getDMMF  Using given datamodel +0ms
  prisma:getDMMF  error of type "wasm-error" in getDmmfWasm:
 {
  reason: '(get-dmmf wasm)',
  error: TypeError [ERR_ENCODING_INVALID_ENCODED_DATA]: The encoded data was not valid for encoding utf-8
      at new NodeError (node:internal/errors:387:5)
      at TextDecoder.decode (node:internal/encoding:433:15)
      at getStringFromWasm0 (/Users/j42/Repros/8525/node_modules/prisma/build/index.js:13201:32)
      at Object.module2.exports.get_dmmf (/Users/j42/Repros/8525/node_modules/prisma/build/index.js:13333:16)
      at tryCatch.type (/Users/j42/Repros/8525/node_modules/prisma/build/index.js:83422:60)
      at tryCatch (/Users/j42/Repros/8525/node_modules/prisma/build/index.js:81856:19)
      at /Users/j42/Repros/8525/node_modules/prisma/build/index.js:83412:9
      at /Users/j42/Repros/8525/node_modules/prisma/build/index.js:82030:39
      at /Users/j42/Repros/8525/node_modules/prisma/build/index.js:82117:14
      at processTicksAndRejections (node:internal/process/task_queues:96:5) {
    errno: 1,
    code: 'ERR_ENCODING_INVALID_ENCODED_DATA'
  }
} +14s
Error: GetDmmfError: (get-dmmf wasm)
Details: The encoded data was not valid for encoding utf-8
[Context: getDmmf]

Prisma CLI Version : 5.1.0
    at /Users/j42/Repros/8525/node_modules/prisma/build/index.js:83475:12
    at n2.e2.run (/Users/j42/Repros/8525/node_modules/prisma/build/index.js:81181:12)
    at n2.e2.exhaustive (/Users/j42/Repros/8525/node_modules/prisma/build/index.js:81163:17)
    at getDMMF (/Users/j42/Repros/8525/node_modules/prisma/build/index.js:83479:6)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async getGenerators (/Users/j42/Repros/8525/node_modules/prisma/build/index.js:91790:16)
    at async _Generate.parse (/Users/j42/Repros/8525/node_modules/prisma/build/index.js:96362:20)
    at async main2 (/Users/j42/Repros/8525/node_modules/prisma/build/index.js:98088:18) 

Can confirm this is reproducible for me as well and you are hitting this issue (and not #12221 which looks similar but is different). We will hopefully be able to look into this soon, thanks to both your reproductions now @tnrich and @rizkyramadhan.

Running the binary CLI manually to get the dmmf for the schema provided above (with the url added) actually works:

set PRISMA_DML_PATH=C:\\Users\\Jan\\Documents\\throwaway\\9417\\prisma\\schema.prisma
"C:\\Users\\Jan\\Documents\\throwaway\\9417\\node_modules\\prisma\\query-engine-windows.exe" --enable-raw-queries cli dmmf

This creates a 1.34 GB Json string with 44.763.742 lines.

Running this a few more times gives other, interesting errors like this one:

Error: Cannot create a string longer than 0x1fffffe8 characters
    at StringDecoder.write (string_decoder.js:84:10)
    at readableAddChunk (internal/streams/readable.js:259:31)
    at PassThrough.Readable.push (internal/streams/readable.js:204:10)
    at PassThrough.Transform.push (internal/streams/transform.js:166:32)
    at PassThrough.afterTransform (internal/streams/transform.js:101:10)
    at PassThrough._transform (internal/streams/passthrough.js:46:3)
    at PassThrough.Transform._read (internal/streams/transform.js:205:10)
    at PassThrough.Transform._write (internal/streams/transform.js:193:12)
    at writeOrBuffer (internal/streams/writable.js:358:12)
    at PassThrough.Writable.write (internal/streams/writable.js:303:10)
  prisma:cli Error: Cannot create a string longer than 0x1fffffe8 characters
  prisma:cli     at StringDecoder.write (string_decoder.js:84:10)
  prisma:cli     at readableAddChunk (internal/streams/readable.js:259:31)
  prisma:cli     at PassThrough.Readable.push (internal/streams/readable.js:204:10)
  prisma:cli     at PassThrough.Transform.push (internal/streams/transform.js:166:32)
  prisma:cli     at PassThrough.afterTransform (internal/streams/transform.js:101:10)
  prisma:cli     at PassThrough._transform (internal/streams/passthrough.js:46:3)
  prisma:cli     at PassThrough.Transform._read (internal/streams/transform.js:205:10)
  prisma:cli     at PassThrough.Transform._write (internal/streams/transform.js:193:12)
  prisma:cli     at writeOrBuffer (internal/streams/writable.js:358:12)
  prisma:cli     at PassThrough.Writable.write (internal/streams/writable.js:303:10) +0ms

I can see the Query Engine process taking full CPU cores and quickly eating up memory (up to 2.6GB) before it crashes.