P
Prisma5w ago
t4u

Logging client errors

Why the following code does not work? The create statement throws a Prisma.PrismaClientKnownRequestError with code P2002 (unique constraint violation). I don't need specific error handling (https://www.prisma.io/docs/orm/prisma-client/debugging-and-troubleshooting/handling-exceptions-and-errors), just a raw console.log of the error.
Handling exceptions and errors (Reference) | Prisma Documentation
This page covers how to handle exceptions and errors
No description
6 Replies
Nurul
Nurul5w ago
Hey @t4ut4ut4u 👋 In this case it looks like console is null? Where are you deploying your app? Are you running this locally?
t4u
t4uOP5w ago
Hi, yes i am running locally. Here my deps:
"dependencies": {
"@mantine/core": "^7.15.2",
"@mantine/dates": "^7.15.2",
"@mantine/form": "^7.15.2",
"@mantine/hooks": "^7.15.2",
"@mantine/modals": "^7.15.2",
"@mantine/notifications": "^7.15.2",
"@prisma/client": "^6.1.0",
"@tabler/icons-react": "^3.26.0",
"bcrypt": "^5.1.1",
"dayjs": "^1.11.13",
"jose": "^5.9.6",
"next": "15.1.3",
"next-safe-action": "^7.10.2",
"nextjs-toploader": "^3.7.15",
"prisma": "^6.1.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"zod": "^3.24.1"
},
"devDependencies": {
"@eslint/eslintrc": "^3",
"@types/bcrypt": "^5.0.2",
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"eslint": "^9",
"eslint-config-next": "15.1.3",
"postcss": "^8.4.49",
"postcss-preset-mantine": "^1.17.0",
"postcss-simple-vars": "^7.0.1",
"prettier": "^3.4.2",
"prettier-plugin-tailwindcss": "^0.6.9",
"tailwindcss": "^3.4.1",
"typescript": "^5"
}
"dependencies": {
"@mantine/core": "^7.15.2",
"@mantine/dates": "^7.15.2",
"@mantine/form": "^7.15.2",
"@mantine/hooks": "^7.15.2",
"@mantine/modals": "^7.15.2",
"@mantine/notifications": "^7.15.2",
"@prisma/client": "^6.1.0",
"@tabler/icons-react": "^3.26.0",
"bcrypt": "^5.1.1",
"dayjs": "^1.11.13",
"jose": "^5.9.6",
"next": "15.1.3",
"next-safe-action": "^7.10.2",
"nextjs-toploader": "^3.7.15",
"prisma": "^6.1.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"zod": "^3.24.1"
},
"devDependencies": {
"@eslint/eslintrc": "^3",
"@types/bcrypt": "^5.0.2",
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"eslint": "^9",
"eslint-config-next": "15.1.3",
"postcss": "^8.4.49",
"postcss-preset-mantine": "^1.17.0",
"postcss-simple-vars": "^7.0.1",
"prettier": "^3.4.2",
"prettier-plugin-tailwindcss": "^0.6.9",
"tailwindcss": "^3.4.1",
"typescript": "^5"
}
Nurul
Nurul5w ago
I am wondering if this has something to do with console object. Can you do a console.log("Something"); in your try block and see if that works? If it works, then we can rule out something being wrong with console
t4u
t4uOP5w ago
yes, console.log with random string works. Don't know if it can help but I am inside a server action (using https://next-safe-action.dev/).
No description
t4u
t4uOP4w ago
@Nurul Hi, I noticed that wrapping the error with JSON.stringify works.
Nurul
Nurul4w ago
Ah, that's great! Thanks for letting me know 👍

Did you find this page helpful?