Registry / devops / prisma-error-formatter

prisma-error-formatter

JSON →
library5.0.0jsnpmunverified

A TypeScript library v5.0.0 for formatting Prisma Client errors into user-friendly, consistent messages. Supports known request errors (unique constraint, foreign key, not found), validation errors, initialization errors, and panic errors. Allows custom formatting via callback. Requires @nestjs/common ^10.0.0, @nestjs/core ^10.0.0, @prisma/client >=4.0.0. Actively maintained on GitHub with MIT license. Differentiated by structured output with path/message and full NestJS integration.

npm install prisma-error-formatter
INSTALL
IMPORT
SIG · PRISMA-ERROR-FORMA
P
prisma-error-formatter
devopsjavascriptv5.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

PrismaExceptionFormatter
✓ import { PrismaExceptionFormatter } from 'prisma-error-formatter'
✗ const PrismaExceptionFormatter = require('prisma-error-formatter')
ESM-only; CJS require will not work. Named export.
ErrorMessage
✓ import { ErrorMessage } from 'prisma-error-formatter'
✗ import { ErrorMessage } from 'prisma-error-formatter/types'
Type exported from main package, not a separate path.
FormatFunction
✓ import type { FormatFunction } from 'prisma-error-formatter'
✗ import { FormatFunction } from 'prisma-error-formatter'
Use type import to avoid runtime side effects.

Creates a PrismaExceptionFormatter and uses it to catch and format a Prisma error in a create operation.

import { PrismaClient } from '@prisma/client'; import { PrismaExceptionFormatter } from 'prisma-error-formatter'; const prisma = new PrismaClient(); const formatter = new PrismaExceptionFormatter(); async function run() { try { await prisma.user.create({ data: { email: 'test@example.com' } }); } catch (error) { const errors = formatter.formatError(error); console.log(errors); // Example: [{ path: 'email', message: 'A record with this email already exists.' }] } finally { await prisma.$disconnect(); } } run();
Debug
Known issues
breakingVersion 5.0.0 changed the API: former single export is now PrismaExceptionFormatter class.
fix
Update import from older versions. Import { PrismaExceptionFormatter } from 'prisma-error-formatter'.
affects: >=5.0.0
deprecatedMethods formatPrismaError, formatQueryError, formatInitializationError are deprecated in v5. Use formatError instead.
fix
Replace calls to deprecated methods with formatter.formatError(error).
affects: >=5.0.0
gotchaPrismaExceptionFormatter is a class, not a function. Must call new PrismaExceptionFormatter().
fix
Use new PrismaExceptionFormatter() instead of PrismaExceptionFormatter().
affects: >=5.0.0
gotchaThe package is ESM-only; CommonJS require() throws a runtime error.
fix
Use ESM imports (import) or dynamic import() in CJS.
affects: >=5.0.0
gotchaPeer dependencies @nestjs/common and @nestjs/core are required for NestJS exception filter use, but not for standalone use.
fix
Install @nestjs/common and @nestjs/core if using with NestJS, otherwise ignore.
affects: >=5.0.0
Errors
Common errors & fixes
TypeError: PrismaExceptionFormatter is not a constructor
Trying to call PrismaExceptionFormatter() without new, or importing as default import in older version.
fix
Use new PrismaExceptionFormatter() and ensure named import: import { PrismaExceptionFormatter } from 'prisma-error-formatter'.
Cannot find module 'prisma-error-formatter' or its corresponding type declarations.
Package not installed or TypeScript not configured for ESM resolution.
fix
Run npm install prisma-error-formatter. In tsconfig.json, set moduleResolution to 'node16' or 'nodenext'.
Upgrade
Version history
5.0.0latest on npm
Audit
Dependencies
@nestjs/commonoptionalPeer dependency for NestJS integration
@nestjs/coreoptionalPeer dependency for NestJS integration
@prisma/clientrequiredPeer dependency for Prisma error types
Agent activity
2 hits · last 30 days
node
2
Resources
prisma-error-formatter — npm install prisma-error-formatter · libregistry