Diagnose missing data
A create or update operation omits required input.
Prisma · Class
PrismaClientValidationError is thrown when Prisma Client input validation fails, such as when required data is missing or a field receives an incompatible type. Its documented properties are message and clientVersion.
Prisma Client raises this exception before completing a query when supplied input fails validation, such as when required data is missing or a value has the wrong type. The exception exposes the validation message and the Prisma Client version.
new Prisma.PrismaClientValidationError(message, clientVersion)Throws an exception when Prisma Client validation fails; the exception exposes message and clientVersion.
import { PrismaClient, Prisma } from "@prisma/client";
const prisma = new PrismaClient();
async function main() {
try {
await prisma.user.create({ data: {} });
} catch (error) {
if (error instanceof Prisma.PrismaClientValidationError) {
console.error(error.message);
}
} finally {
await prisma.$disconnect();
}
}
main();Attempts a create operation with missing data, then recognizes and reports the validation exception.
A create or update operation omits required input.
A query supplies a value incompatible with the model field type.
An application needs version-aware Prisma diagnostics.
PrismaClientValidationError is thrown when Prisma Client input validation fails. The documentation gives missing fields and incorrect field types as examples.
Follow-up: How would you distinguish it from a known request error? Check the exception type with instanceof; validation errors concern invalid client input, whereas known request errors represent documented database or query-engine request failures.
The documented properties are message, which contains the error message, and clientVersion, which identifies the Prisma Client version.
Follow-up: Which property is most useful for presenting diagnostic details? The message property, while clientVersion helps correlate behavior with the generated client version.
Catch the exception and inspect its message after correcting the invalid query input. For TypeScript, the Prisma namespace exposes PrismaClientValidationError for type-based handling.
Follow-up: What should be fixed first after catching it? Correct the missing field or incompatible value described by the validation message, rather than retrying the unchanged query.
PrismaClientKnownRequestErrorPrismaClientUnknownRequestErrorPrismaClientInitializationErrorPrismaClientRustPanicError