in reply to Re: Mapping database errors to user errors
in thread Mapping database errors to user errors
If you don’t want the user to see the nitty-gritty, there’s no point in parsing it before showing it to them – just don’t show it at all. Trap the error and make it a generic “Something went wrong” message to the user, and dump the real message to the error log.
Sorry, no. If a user fills a registration form and picks a username that already exists, and the database rejects the row because it violates the uniqueness constraint, I don’t want to tell the user “something went wrong,” nor do I want to tell them “column username is not unique(1) at dbdimp.c line 397.” I want to tell them “the username you picked is taken, please try another.”
Don’t repeat good-sounding advice without understanding where it applies.
Even better is to try to trap the conditions that create the error
That’s not very clever either. Now you have to keep the database schema constraints and the application error checks in synch – a violation of Don’t Repeat Yourself.
I’ve been thinking about this particular problem of mapping from schema constraint violations to user error messages, lately. It’s neither a trivial problem nor one that anyone seems to have done much work on. The usual answer is the one you gave – check constraints in the client code. The more clueful people will advise to check only in the client code, to avoid the synchronisation problems. I don’t think that’s anything approaching a good answer. The constraints belong in the schema; all else violates separation of concerns.
Some means of annotating constraints is the solution, but what form it should take is a hard question.
Makeshifts last the longest.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Mapping database errors to user errors
by Ovid (Cardinal) on Nov 26, 2005 at 06:01 UTC | |
|
Re^3: Mapping database errors to user errors
by qq (Hermit) on Nov 27, 2005 at 17:27 UTC | |
by Aristotle (Chancellor) on Nov 27, 2005 at 18:26 UTC |