Repository navigation
Have TranslateError wrap the error instead
#7750
jared-mackey
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
For the most part in our codebase we want just the translated errors and don't really care about the underlying driver error. We love to use
gorm.ErrRecordNotFoundand the likes for the most part. However, there are cases when we need to access the underlying PG error of one of the errors that's been translated. For example, say you have a table with 2 unique constraints on it and you need to handle them differently you would do something like this without error translation:However, with TranslateError enabled it's not possible to do
errors.As(tx.Error, &pgErr)or check the constraint that's failing at all as the error is not wrapped with the original pg error.My proposal is to change the dialect translator to do this instead:
This seems like a straightforward change and I believe users of the library will still be able to do
errors.Is(err, gorm.ErrRecordNotFound)and the likes on all the translated errors fine. Are there other downsides to changing this to a wrap? Are there other backwards incompatibilities I'm not thinking of here? Is there an existing workaround I'm not considering?All reactions