Raising ActiveRecord::StatementInvalid as the single exception for
anything that might go wrong is rather unspecific. There are
differences between exceptions, some signify plain programming errors,
others are caused by potentially recoverable faults. Specifically among
the later are violations of uniqueness constraints.
Differentiating among the original causes in application or plugin code
is rather nasty and potentially brittle as most developers only care
about one or two DBMS. I suggest to push this functionality into the
connection adapters and have them at least handle uniqueness violations
specially by raising RecordNotUnique, subclassed from StatementInvalid,
with a suitable hint as to which constraint has been violated.
Are there any general concerns against adding this functionality?
Otherwise, I'll start work on a patch.
Raising ActiveRecord::StatementInvalid as the single exception for
anything that might go wrong is rather unspecific. There are
differences between exceptions, some signify plain programming errors,
others are caused by potentially recoverable faults. Specifically among
the later are violations of uniqueness constraints.
Differentiating among the original causes in application or plugin code
is rather nasty and potentially brittle as most developers only care
about one or two DBMS. I suggest to push this functionality into the
connection adapters and have them at least handle uniqueness violations
specially by raising RecordNotUnique, subclassed from StatementInvalid,
with a suitable hint as to which constraint has been violated.
Are there any general concerns against adding this functionality?
Otherwise, I'll start work on a patch.
I'd love this, it's one of the things I really liked about spring from
my java days. rescuing ForeignKeyContraintViolation or
DeadlockLoserException etc would be great.
> Are there any general concerns against adding this functionality?
> Otherwise, I'll start work on a patch.
I'd love this, it's one of the things I really liked about spring
from my java days. rescuing ForeignKeyContraintViolation or
DeadlockLoserException etc would be great.
For the time being, only violated uniqueness constraints and invalid
foreign keys are handled specially. I don't know how to detect or
test(!) things like DeadlockLoserException. Anyone, please fill in any
blanks you perceive.
Are there any further suggestions and opinions regarding this patch? For
my purposes, it does all I need, right now. A major improvement would
be enabled if the pg gem (PostgreSQL driver) passed on error codes --
is there any chance of this happening?