prisma / prisma-client-js

Type-safe database client for TypeScript & Node.js (ORM replacement)
Apache License 2.0
1.47k stars 67 forks source link

Change default error formatting from `pretty` to `colorless` #579

Closed schickling closed 4 years ago

schickling commented 4 years ago

Problem

When an error is thrown in Prisma Client currently the error is "pretty printed" by default (see spec) which is making use of ASCII colors. While this provides a better DX in environments which support ASCII colors, in environments that don't provide support this results in unreadable error messages. See the list of issues below for reference:

When a user runs into this situation (i.e. an error is thrown in an environment that doesn't support ASCII colors) the error message is barely readable. While it's theoretically possible that in these cases a user could manually disable colored error formatting by setting errorFormat: 'colorless' it's an unrealistic assumption that a user would know (or intuitively assume) that the error formatting can be configured in order to get a more readable output. To make matters worse often it might be really hard to reproduce an error due to the non-idempotent nature of most applications so even if a user has figured out how to configure the error formatting correctly it might be a lot of work to reproduce the error.

Solution

I suggest to change the default error formatting from pretty to colorless in order to avoid the problem described above. I'm all in favor of trying to provide the best possible DX out of the box without further configuration but we need to do so in a safe way that avoids negative surprise.

Once we've changed the default error formatting, I suggest to collaborate with framework authors (e.g. Redwood, Nexus, ...) so these frameworks enable pretty error formatting out of the box as they can guarantee a safe environment.

We should also investigate whether there are better heuristics to safely determine whether an environment support ASCII colors.

Jolg42 commented 4 years ago

Current implemented specification is here https://github.com/prisma/specs/blob/master/prisma-client-js/README.md#error-formatting

macrozone commented 4 years ago

@schickling agree. I just yesterday found out about the the formatting option. We mostly saw this errors in graphql requests, so there the pretty formatting is unreadable

Jolg42 commented 4 years ago

Done in c7e8afc Spec up-to-date https://github.com/prisma/specs/tree/master/prisma-client-js