edgedb-go icon indicating copy to clipboard operation
edgedb-go copied to clipboard

Get details of ConstraintViolationError

Open divan opened this issue 2 years ago • 5 comments

Is it possible to extract information about constraint violation error from edgedb.Error?

Idea is that I'm interested in knowing which field exactly has violated constraints (say, is it an email field of User or something else), so the different actions can be taken.

Seems like right now the only way is to parse a string "email violates exclusivity constraint", which is not reliable way in a long term.

divan avatar Mar 27 '23 00:03 divan

I don't think that there is structured information like that by default. I may be wrong though. I'll double check tomorrow. However, you can override the error message with whatever you want including structured data like json. You will still have to parse it, but its better than parsing an error message.

fmoor avatar Mar 27 '23 03:03 fmoor

Here is a link to the relevant documentation. errmessage is the bit that changes the message.

fmoor avatar Mar 27 '23 03:03 fmoor

I confirmed that the server doesn't send any structured data that indicates which constraint has been violated.

fmoor avatar Mar 27 '23 18:03 fmoor

@fmoor thanks! Not high a priority, but would be nice to have it someday to make error handling more reliable.

divan avatar Mar 28 '23 05:03 divan

For whoever stumbles on this issue, we plan to refactor errors in EdgeQL it self. This will improve a lot of things. Information about constraint violations being one of them.

fmoor avatar Oct 03 '23 21:10 fmoor

I'm going to close this because there is no way to improve the situation until errors are refactored in the query language.

fmoor avatar Mar 06 '25 19:03 fmoor