more useful options | |
PerlMonks |
Re^2: Mapping database errors to user errorsby Aristotle (Chancellor) |
on Nov 26, 2005 at 01:25 UTC ( [id://511791]=note: print w/replies, xml ) | Need Help?? |
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.
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.
In Section
Seekers of Perl Wisdom
|
|