Add custom error message on object level security constraints
Currently, when a access policy constraint is violated the error looks like this:
edgedb error: EdgeDBError: access policy violation on insert of default::User
It does not carry any info about what constraint has been violated (it can have more than 1 insert constraint for eg).
Would be great to be able to set a custom error message like we do on type/field level constraints.
There's some design work needed to figure out exactly what error message should be output. An access policy is violated if one or two things happens:
- Every allow rule is false
- Some reject rule is true
If a reject rule is false, we should output the error message for it. The main question, then, is what to do for allow. I propose that on errors we include the text of every relevant error message, which is to say:
- For every allow rule if they are all false, otherwise none of them
- The error message for each reject rule that is true Then we'll omit mentioning any rule without a message specified.
From an implementation perspective, we'll need to keep the policy expressions separate in the IR for DML, and track the error messages we want. Currently we combine them all together first, here: https://github.com/edgedb/edgedb/blob/ccbff2bd328fd3738619c000729685d5e4bfdf56/edb/edgeql/compiler/policies.py#L121-L177