Skip to content

RangeError: Invalid count value during create #4083

@dpankros

Description

@dpankros

When performing a transaction-bound create (with a bunch of sub-creates), I'm getting:

RangeError: Invalid count value
    at String.repeat (<anonymous>)
    at Object.transformLine (/Users/dpankros/Development/workflow-test/server/node_modules/@prisma/client/runtime/src/runtime/utils/printJsonErrors.ts:120:42)
    at /Users/dpankros/Development/workflow-test/server/node_modules/@prisma/client/runtime/src/runtime/utils/stringifyObject.ts:157:30
    at Array.map (<anonymous>)
    at i (/Users/dpankros/Development/workflow-test/server/node_modules/@prisma/client/runtime/src/runtime/utils/stringifyObject.ts:132:12)
    at /Users/dpankros/Development/workflow-test/server/node_modules/@prisma/client/runtime/src/runtime/utils/stringifyObject.ts:144:25
    at Array.map (<anonymous>)
    at i (/Users/dpankros/Development/workflow-test/server/node_modules/@prisma/client/runtime/src/runtime/utils/stringifyObject.ts:132:12)
    at /Users/dpankros/Development/workflow-test/server/node_modules/@prisma/client/runtime/src/runtime/utils/stringifyObject.ts:144:25
    at Array.map (<anonymous>)

Unfortunately, I cannot provide a reproducible chunk of code at this point as it is a bit involved, but I do have a theory

Referencing this bit of code, and reproduced below:

  if (typeof value === 'object') {
    return (
      getLongestLine(`${key}: ${stripAnsi(stringifiedValue)}`) - indent.length. // THIS LINE HERE
    )
  }

The only way I can see this error occurring, is if in the referenced line, getLongestLine returns a value less than indent.length (say, zero). If that's the case, getValueLength returns a negative number, which is passed as the argument to '~'.repeat() and negative values or Infinity passed to String.repeat, cause the 'Invalid count value' error.

If that theory is correct, a quick guard against this would be:

      Math.max(getLongestLine(`${key}: ${stripAnsi(stringifiedValue)}`) - indent.length, 0)

Environment

$ npx prisma --version
Environment variables loaded from package.json configuration at src/prisma/.env
@prisma/cli : 2.9.0
@prisma/client : 2.9.0
Current platform : darwin
Query Engine : query-engine 369b369 (at node_modules/@prisma/cli/query-engine-darwin)
Migration Engine : migration-engine-cli 369b369 (at node_modules/@prisma/cli/migration-engine-darwin)
Introspection Engine : introspection-core 369b369 (at node_modules/@prisma/cli/introspection-engine-darwin)
Format Binary : prisma-fmt 369b369 (at node_modules/@prisma/cli/prisma-fmt-darwin)
Studio : 0.296.0
Preview Features : transactionApi

node --version
v12.19.0

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions