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

Remove unnecessary exception catching #1224

Merged
merged 1 commit into from
Jan 29, 2019

Conversation

davesque
Copy link
Contributor

What was wrong?

Exceptions generated by eth-abi are fairly descriptive. It seems a bit
redundant to wrap encoding exceptions with this extra message and also
filter out the original exception type.

Also, some code wrapped in this try/except block could never throw EncodingError exceptions.

I poked around and it doesn't look like any dependent code is expecting a TypeError specifically. Also, the test suite still seems to pass. So I'm not sure if there's much risk here.

How was it fixed?

Removed the relevant try/except block.

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

@davesque davesque requested a review from carver January 24, 2019 22:44
Exceptions generated by eth-abi are fairly descriptive.  It seems a bit
redundant to wrap encoding exceptions with this extra message and also
filter out the original exception type.
Copy link
Collaborator

@carver carver left a comment

Choose a reason for hiding this comment

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

Yeah, I think the argument was roughly that end-user libraries, like web3, should avoid raising custom exceptions, preferring builtins. I think I still like that approach in general, but don't feel strongly about it. Up to you 👍

@davesque
Copy link
Contributor Author

@carver

What's the reasoning behind that? Is it that it's annoying to have to import exceptions to catch them?

I think I noticed that and tried to follow suit, but eventually I got frustrated that there isn't always a built-in exception that seems appropriate for the given situation. Then, I just broke down and went back to having a custom set of Exception subclasses for the library.

One reason I kinda like that is exceptions can more directly correspond to the task that's being done e.g. EncodingError getting raised during encoding of values.

@davesque
Copy link
Contributor Author

davesque commented Jan 29, 2019

This situation is a good example of what I'm talking about, by the way. It's confusing that TypeError is being raised to signal some problem with encoding a certain value. I might have expected that ValueError would be raised. It seems like the appropriate use of those two built-ins can sometimes be a bit subjective and different people's preferences might not be consistent with each other. On the other hand, I don't feel like anyone would be confused if something called EncodingError was raised when calling something named encode_abi.

@davesque davesque merged commit 5086c1c into ethereum:master Jan 29, 2019
@davesque davesque deleted the exc-catching branch January 30, 2019 22:22
@carver
Copy link
Collaborator

carver commented Feb 5, 2019

What's the reasoning behind that? Is it that it's annoying to have to import exceptions to catch them?

Yeah, that seems about right. Roughly that the global exceptions are a nice standard to rally around. When possible, it's better to stick to a global standard than a project-level one. Like I said, not a strong feeling though (at a basic level, someone naturally has to learn your API to work with your library).

I don't feel like anyone would be confused if something called EncodingError was raised when calling something named encode_abi.

Sounds good to me 👍

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.

3 participants