edgedb / edgedb-go

The official Go client library for EdgeDB
https://pkg.go.dev/github.com/edgedb/edgedb-go
Apache License 2.0
168 stars 11 forks source link

Get details of ConstraintViolationError #269

Open divan opened 1 year ago

divan commented 1 year ago

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.

fmoor commented 1 year ago

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 commented 1 year ago

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

fmoor commented 1 year ago

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

divan commented 1 year ago

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

fmoor commented 9 months ago

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.