-
Notifications
You must be signed in to change notification settings - Fork 390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve json cast error messages #7312
Conversation
5a7556f
to
0a26748
Compare
Looks bigger than it is :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, and will be a nice improvement.
Remember to bump EDGEDB_CATALOG_VERSION
edb/edgeql/compiler/casts.py
Outdated
qlast.Constant.boolean(allow_null), | ||
] | ||
if error_message_context := cast_message_context(subctx): | ||
detail = qlast.Constant.string( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be cleaner to build the dict and json.dumps
it
@@ -85,6 +85,31 @@ std::json_get( | |||
$$; | |||
}; | |||
|
|||
|
|||
CREATE FUNCTION |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want this because it produces a better error message than leaving it to the cast, or what?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function lets us produce different error messages for when a tuple is missing an element and when the element is there but explicitly set to null.
error_message_context = '' | ||
if err_details.detail_json: | ||
error_message_context = ( | ||
err_details.detail_json.get('error_message_context', '') | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The big question for me with this PR is:
Is it better to have the context prepended to the actual message, or would it be better to put it in the details
field?
My inclination had been details
, but this looks pretty nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess either works, but it seemed to me that details were often more about providing information from beyond the immediate context. (eg. stuff about the inheritance of the types involved in an error)
Provide context to error messages when casting to from json to collections.
Given
SELECT <tuple<a: int64>>to_json('{"b": 1}');
the following error is produced:Given
SELECT <tuple<a: int64>>to_json('{"a": "b"}');
the following error is produced: