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

refactor catch-all exceptions #545

Merged
merged 1 commit into from
Nov 15, 2017
Merged

Conversation

mvalkon
Copy link
Collaborator

@mvalkon mvalkon commented Nov 14, 2017

The flake8 checks were failing for py3.5 due to a couple of catch-all
exceptions when importing tornado and gevent libraries. Refactored to
catch the ImportError.

The flake8 checks were failing for py3.5 due to a couple of catch-all
exceptions when importing tornado and gevent libraries. Refactored to
catch the `ImportError`
@mvalkon
Copy link
Collaborator Author

mvalkon commented Nov 14, 2017

I am actually of the opinion to remove catching the exceptions at all, since we're now essentially converting the ImportError to an Exception.

@coveralls
Copy link

coveralls commented Nov 14, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling fc01d69 on mvalkon:fix/flake8 into f846126 on zalando:master.

@@ -97,7 +97,7 @@ def run(self, port=None, server=None, debug=None, host=None, **options): # prag
import tornado.wsgi
import tornado.httpserver
import tornado.ioloop
except:
except ImportError:
raise Exception('tornado library not installed')
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess for this purpose raising RuntimeError(...) would be more appropriate

Copy link
Collaborator Author

@mvalkon mvalkon Nov 14, 2017

Choose a reason for hiding this comment

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

At least it is more specific than an Exception, I can change it.

However regardless of which exception is raised, the application terminates. Given that the server is a user provided parameter, isn't letting the ImportError bubble up to the cli the clearest way of informing the user that the library they want to use is not installed?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not always. ImportError may also indicate that PYTHONPATH is wrong. I think the biggest value here is the error description or the message the user sees and it's quite clear.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Perhaps my wording was poor, but that is exactly what I meant, the library cannot be found.

>>> import tornado
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'tornado'

vs

>>> raise RuntimeError("Module 'tornado' cannot be found")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: Module 'tornado' cannot be found

I think we're splitting hairs now 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

I just pointed to the fact the there are at least two reasons why module can't be found: it's not installed or it's installed but PYTONPATH is wrong and should we do pip install or check our environment variables. So it's kind of make sense to be precise here when it comes to debugging.
To me, giving the message that it's not installed (which is more probable) is better than just the module is not found, purely for debug reasons

@prawn-cake
Copy link
Contributor

👍

1 similar comment
@hjacobs
Copy link
Contributor

hjacobs commented Nov 15, 2017

👍

@hjacobs hjacobs merged commit 0918a9e into spec-first:master Nov 15, 2017
@mvalkon mvalkon deleted the fix/flake8 branch November 15, 2017 07:36
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.

4 participants