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

Modify config #30

Merged
merged 3 commits into from May 25, 2016
Merged

Modify config #30

merged 3 commits into from May 25, 2016

Conversation

willkg
Copy link
Collaborator

@willkg willkg commented May 25, 2016

This tweaks configuration a little bit to make it easier to work with in the breakpad code I'm writing.

The only new feature is the parse_class parser. That should be pretty straight-forward.

The rest of it is nixing the config singleton for one that's instantiated when the app is created.

This reworks how configuration works so instead of it being global, it's
now bound to a Falcon API instance through get_app() and then passed to
the resources.

This will make it easier to have instance-specific configuration where
two instances of the same class can have different configuration
differentiated by namespace.
This lets us import classes from a spec string.
@willkg
Copy link
Collaborator Author

willkg commented May 25, 2016

@peterbe Can you do a quick r? for python-y issues and a sanity check?

I accidentally unindented this. Fixing it.
try:
return getattr(module, class_name)
except AttributeError:
raise ValueError('%s is not a valid member of %s' % (
Copy link

Choose a reason for hiding this comment

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

Why a ValueError? What was wrong with the AttributeError? Also, might it be of interest to re-wrap it as ImportError?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We could return the AttributeError, my initial tinkering suggested it wasn't wildly helpful and that a better error messages was. Without this wrapping, you get something like:

>>> import importlib
>>> module = importlib.import_module('hashlib')
>>> getattr(hashlib, 'foo')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'foo'
>>> 

"module" is totally not helpful here. With my changes, you get something like:

ValueError: 'foo' is not a valid member of hashlib'

I thought about wrapping the ImportError and then decided not to because the ImportError itself is more informative than what I'd probably do if wrapping it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Continuing, I think the actual exception is moot. This is something that the developer is seeing when they're implementing something and a user is seeing if they've got antenna configured wrong. It's not an exception that is intended to be caught and handled.

I'm on the fence. I think I want to hedge towards users being able to see the message and intuit what to do next. I don't know what to do to make it better.

With Python 3, this is much easier since you can chain exceptions. Then we could throw an additional ConfigurationError with a super helpful message and the user gets our message plus the original one.

@peterbe
Copy link

peterbe commented May 25, 2016

r+

@willkg
Copy link
Collaborator Author

willkg commented May 25, 2016

Thank you!

@willkg willkg merged commit b44c2df into mozilla-services:master May 25, 2016
@willkg willkg deleted the modify-config branch May 25, 2016 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants