Skip to content

Commit

Permalink
Merge pull request #487 from plotly/bare-exceptions
Browse files Browse the repository at this point in the history
Bare exceptions
  • Loading branch information
Shammamah Hossain authored Dec 14, 2018
2 parents 75a285f + 3a69377 commit 50c6c41
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
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'

0 comments on commit 50c6c41

Please sign in to comment.