Skip to content
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

More verbose error messages #66

Merged
merged 5 commits into from
Feb 15, 2022

Conversation

FedericoV
Copy link
Contributor

Makes the error messages a bit more verbose in a few places, with information about types and values.

Gives more information about why the error failed.
Gives more information about why the error failed.
Copy link
Owner

@patrick-kidger patrick-kidger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I apologise for doing this ;)

@@ -599,7 +599,8 @@ def diffeqsolve(

# Error checking
if dt0 is not None:
error_if(lambda: (t1 - t0) * dt0 <= 0, "Must have (t1 - t0) * dt0 > 0")
msg = f"Must have (t1 ({t1, type(t1)}) - t0 ({t0, type(t0)})) * dt0 ({dt0, type(dt0)})> 0"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I find this a little hard to read. Can the f"{}" values be collected at the end of the error message?
When printing out a type, can we use plain English to denote what's going on, e.g. Got value {t1} of type {type(t1)}.

"`pred` must either be a `bool`, a NumPy array, a JAX array, or a "
"zero-argument callable that returns a `bool` or JAX array."
f"`pred` {pred} must either be a `bool`, a JAX array, or a zero-argument callable "
f"that returns a `bool` or JAX array, instead of {type(pred)}."
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd don't hold to this as a hard-and-fast rule, but for something like this where an error here can almost only ever occur due to something totally crazy: I'd recommend putting the f"{}" values at the end of the docstring. That way if they're something with a huge __str__ they won't blat the rest of the error message that comes after them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good :)

Let me know if this looks better.

Error messages now have type and value information and the end.
@patrick-kidger
Copy link
Owner

LGTM! I'll merge once the tests pass and we'll fold this into the 0.0.3 release.

@patrick-kidger
Copy link
Owner

...if the tests pass, haha.

It looks you haven't set up the pre-commit hooks. See CONTRIBUTING.md.

@patrick-kidger patrick-kidger merged commit cc34f26 into patrick-kidger:main Feb 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants