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

Bare exceptions #487

Merged
merged 7 commits into from
Dec 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.33.0 - 2018-12-10
## Added
- Added specific Dash exception types to replace generic exceptions (InvalidIndexException, DependencyException, ResourceException) [#487](https://github.com/plotly/dash/pull/487)

## 0.32.2 - 2018-12-09
## Fixed
- Fix typo in missing events/inputs error message [#485](https://github.com/plotly/dash/pull/485)
Expand Down
10 changes: 5 additions & 5 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def _layout_value(self):
def layout(self, value):
if (not isinstance(value, Component) and
not isinstance(value, collections.Callable)):
raise Exception(
raise exceptions.NoLayoutException(
''
'Layout must be a dash component '
'or a function that returns '
Expand All @@ -301,7 +301,7 @@ def index_string(self, value):
)
missing = [missing for check, missing in checks if not check]
if missing:
raise Exception(
raise exceptions.InvalidIndexException(
'Did you forget to include {} in your index string ?'.format(
', '.join('{%' + x + '%}' for x in missing)
)
Expand Down Expand Up @@ -475,14 +475,14 @@ def _generate_meta_html(self):
# Serve the JS bundles for each package
def serve_component_suites(self, package_name, path_in_package_dist):
if package_name not in self.registered_paths:
raise exceptions.InvalidResourceError(
raise exceptions.DependencyException(
'Error loading dependency.\n'
'"{}" is not a registered library.\n'
'Registered libraries are: {}'
.format(package_name, list(self.registered_paths.keys())))

elif path_in_package_dist not in self.registered_paths[package_name]:
raise exceptions.InvalidResourceError(
raise exceptions.DependencyException(
'"{}" is registered but the path requested is not valid.\n'
'The path requested: "{}"\n'
'List of registered paths: {}'
Expand Down Expand Up @@ -546,7 +546,7 @@ def index(self, *args, **kwargs): # pylint: disable=unused-argument

if missing:
plural = 's' if len(missing) > 1 else ''
raise Exception(
raise exceptions.InvalidIndexException(
'Missing element{pl} {ids} in index.'.format(
ids=', '.join(missing),
pl=plural
Expand Down
12 changes: 12 additions & 0 deletions dash/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,15 @@ class InvalidConfig(DashException):

class InvalidResourceError(DashException):
pass


class InvalidIndexException(DashException):
pass


class DependencyException(DashException):
pass


class ResourceException(DashException):
pass
3 changes: 2 additions & 1 deletion dash/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os

from .development.base_component import ComponentRegistry
from . import exceptions


# pylint: disable=old-style-class
Expand Down Expand Up @@ -47,7 +48,7 @@ def _filter_resources(self, all_resources, dev_bundles=False):
)
continue
else:
raise Exception(
raise exceptions.ResourceException(
'{} does not have a '
'relative_package_path, absolute_path, or an '
'external_url.'.format(
Expand Down
2 changes: 1 addition & 1 deletion dash/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.32.2'
__version__ = '0.33.0'