-
Notifications
You must be signed in to change notification settings - Fork 256
Better Python Errors #9398
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
Better Python Errors #9398
Conversation
|
One other question: Is it a breaking change to change the type of error we throw? |
patrick-schultz
left a comment
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 is great. Overall design looks good, just a few minor things.
hail/python/hail/ir/base_ir.py
Outdated
| while i < len(stack): | ||
| candidate = stack[i] | ||
| i += 1 | ||
| if any(phrase in candidate for phrase in forbidden_phrases): | ||
| continue | ||
| filt_stack.append(candidate) |
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 this can be simplified to
filt_stack = [
candidate for candidate in stack[i:]
if not any(phrase in candidate for phrase in forbidden_phrases)
]| assert(ev.pt == expectedPType) | ||
| ev | ||
| case Die(m, typ) => | ||
| case @Die(m, typ, errorId) => |
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.
Extraneous @
| Coalesce(FastIndexedSeq( | ||
| extracted.postAggIR, | ||
| Die("Internal error: TableMapRows: row expression missing", extracted.postAggIR.typ)))) | ||
| Die("Internal error: TableMapRows: row expression missing", extracted.postAggIR.typ, -1)))) |
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.
You added the constructor that sets the errorId to -1 implicitly; did you not want to use that here (and several other places)? That would keep the -1 magic number hard coded in fewer places.
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.
Ah, I originally added the numeric argument everywhere manually because I didn't want to miss anywhere where I had to copy the argument along. I can go back now and remove the extras.
|
Thanks for the review, all addressed now. |
| @@ -1,5 +1,6 @@ | |||
| package is.hail.expr.ir | |||
|
|
|||
| import com.google.api.gax.rpc.InvalidArgumentException | |||
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.
delete this?
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.
Oh, that was a mistake where I typed "Invalid" instead of "Illegal", must have autoimported.
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.
yeah, I do that all the time!
… Now need to pass an error id for Die to make an example
a209896 to
0c8cfd3
Compare
* Added error_id to Die in python * WIP on better errors * WIP, I'm now saving an error id in Java and sending it back to Python * Added an ir search to find the ir node where an exception originates. Now need to pass an error id for Die to make an example * Made the connection, just have to cleanup a bit now * Seems to be working * Actually working * Remove pdb * Let's call it hail stack trace instead * IRSuite test fixes * Updated python tests for case builders to verify this is working * Removed extra @ sign * Don't explicitly pass -1 in TableIR * Change filtering approach, add decorator-gen * Delete InvalidArgumentException * Style fixes * Fixed bad HailException constructor * Added HailUserError to things that are exported, catching the right error type in bit shift * Fixed slice and eval tests * biallelic and uniroot throw user errors now too * Fix uniroot and locus windows * locus_windows actually passing now * Copying Die nodes need to preserve the stack trace and error id
This PR is based on discussion here: https://dev.hail.is/t/better-python-error-messages-idea/201/9 The intention is to create a system to give better error messages from python in a generic way. Tim's work in #7792 does a good job introducing behavior like this this specifically for
ArrayRefnodes, but I want to add three things on top of that:This first PR is a proof of concept that adds this behavior for the
Dienode, which will catch any errors generated by uses ofCaseBuilder.or_error. Follow up PRs should changeArrayRefto work this way, as well as catch things like looking up a key in a dictionary but not finding it. In an ideal future, we'd bolt on some extra mechanism to give types to these errors, and we could throw a properIndexErrorin theArrayRefcase orKeyErrorin the dictionary case.It feels a little bit messy right now, open to suggestions. I don't love using
-1as the "no error" situation, but I thought it was probably easier than dealing with optionals between python and scala.To give an example of what it looks like, the error message for this script:
is
(Note that ndarray bounds checking internally uses a case builder, which is why this example works).