Skip to content

Commit

Permalink
replace system errors (#529)
Browse files Browse the repository at this point in the history
This PR replaces Envisage's uses of `SystemError` with more appropriate
exceptions.

Closes #442

---------

Co-authored-by: Chengyu Liu <cyliu@aus552cyliu.local>
  • Loading branch information
homosapien-lcy and Chengyu Liu authored Mar 16, 2023
1 parent 27014dc commit 886381e
Show file tree
Hide file tree
Showing 18 changed files with 25 additions and 26 deletions.
4 changes: 2 additions & 2 deletions envisage/composite_plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def start_plugin(self, plugin=None, plugin_id=None):
logger.debug("plugin %s started", plugin.id)

else:
raise SystemError("no such plugin %s" % plugin_id)
raise ValueError("no such plugin %s" % plugin_id)

def stop(self):
""" Stop the plugin manager. """
Expand All @@ -177,4 +177,4 @@ def stop_plugin(self, plugin=None, plugin_id=None):
logger.debug("plugin %s stopped", plugin.id)

else:
raise SystemError("no such plugin %s" % plugin_id)
raise ValueError("no such plugin %s" % plugin_id)
2 changes: 1 addition & 1 deletion envisage/egg_basket_plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def _harvest_plugins_in_eggs(self, application):
def _handle_broken_distributions(self, errors):
logger.error("Error loading distributions: %s", errors)
if self.on_broken_distribution is None:
raise SystemError("Cannot find eggs %s" % errors)
raise RuntimeError("Cannot find eggs %s" % errors)
else:
for dist, exc in errors.items():
self.on_broken_distribution(dist, exc)
Expand Down
2 changes: 1 addition & 1 deletion envisage/egg_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def add_eggs_on_path(working_set, path, on_error=None):
if on_error:
on_error(errors)
else:
raise SystemError("Cannot find eggs %s" % errors)
raise RuntimeError("Cannot find eggs %s" % errors)

# Add the distributions to the working set (this makes any Python
# modules in the eggs available for importing).
Expand Down
4 changes: 2 additions & 2 deletions envisage/i_plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def start_plugin(self, plugin=None, plugin_id=None):
If a plugin is specified then start it.
If no plugin is specified then the Id is used to look up the plugin
and then start it. If no such plugin exists then a 'SystemError'
and then start it. If no such plugin exists then a 'ValueError'
exception is raised.
"""
Expand All @@ -82,7 +82,7 @@ def stop_plugin(self, plugin=None, plugin_id=None):
If a plugin is specified then stop it (the Id is ignored).
If no plugin is specified then the Id is used to look up the plugin and
then stop it. If no such plugin exists then a 'SystemError' exception
then stop it. If no such plugin exists then a 'ValueError' exception
is raised.
"""
4 changes: 2 additions & 2 deletions envisage/plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def start_plugin(self, plugin=None, plugin_id=None):
logger.debug("plugin %s started", plugin.id)

else:
raise SystemError("no such plugin %s" % plugin_id)
raise ValueError("no such plugin %s" % plugin_id)

def stop(self):
""" Stop the plugin manager. """
Expand All @@ -166,7 +166,7 @@ def stop_plugin(self, plugin=None, plugin_id=None):
logger.debug("plugin %s stopped", plugin.id)

else:
raise SystemError("no such plugin %s" % plugin_id)
raise ValueError("no such plugin %s" % plugin_id)

#### Protected 'PluginManager' ############################################

Expand Down
2 changes: 1 addition & 1 deletion envisage/provider_extension_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ProviderExtensionRegistry(ExtensionRegistry):
def set_extensions(self, extension_point_id, extensions):
""" Set the extensions to an extension point. """

raise SystemError("extension points cannot be set")
raise TypeError("extension points cannot be set")

###########################################################################
# 'ProviderExtensionRegistry' interface.
Expand Down
5 changes: 2 additions & 3 deletions envisage/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
import logging

# Enthought library imports.
from traits.api import TraitType

from traits.api import TraitError, TraitType

# Logging.
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -74,7 +73,7 @@ def get(self, obj, trait_name):
def set(self, obj, name, value):
""" Trait type setter. """

raise SystemError("Service traits cannot be set")
raise TraitError("Service traits cannot be set")

###########################################################################
# Private interface.
Expand Down
4 changes: 2 additions & 2 deletions envisage/tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,11 @@ def test_start_and_stop_errors(self):
application.stop()

# Try to start a non-existent plugin.
with self.assertRaises(SystemError):
with self.assertRaises(ValueError):
application.start_plugin(plugin_id="bogus")

# Try to stop a non-existent plugin.
with self.assertRaises(SystemError):
with self.assertRaises(ValueError):
application.stop_plugin(plugin_id="bogus")

def test_extension_point(self):
Expand Down
2 changes: 1 addition & 1 deletion envisage/tests/test_egg_based.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def _add_eggs_on_path(self, path, working_set=None):
# Py2 tests was checking that len(errors) > 0. This did not work on
# Py3. Test changed to check the len(distributions)
if len(distributions) == 0:
raise SystemError("Cannot find eggs %s" % errors)
raise RuntimeError("Cannot find eggs %s" % errors)

# Add the distributions to the working set (this makes any Python
# modules in the eggs available for importing).
Expand Down
2 changes: 1 addition & 1 deletion envisage/tests/test_egg_basket_plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def test_ignore_broken_distributions_raises_exceptions_by_default(self):
self._create_broken_distribution_eggdir("acme.foo*.egg"),
],
)
with self.assertRaises(SystemError):
with self.assertRaises(RuntimeError):
iter(plugin_manager)

def test_ignore_broken_distributions_loads_good_distributions(self):
Expand Down
2 changes: 1 addition & 1 deletion envisage/tests/test_extension_point_changed.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_set_extension_point(self):
application.start()

# Try to set the extension point.
with self.assertRaises(SystemError):
with self.assertRaises(TypeError):
setattr(a, "x", [1, 2, 3])

def test_mutate_extension_point_no_events(self):
Expand Down
4 changes: 2 additions & 2 deletions envisage/tests/test_plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ def test_start_and_stop_errors(self):
plugin_manager.stop()

# Try to start a non-existent plugin.
with self.assertRaises(SystemError):
with self.assertRaises(ValueError):
plugin_manager.start_plugin(plugin_id="bogus")

# Try to stop a non-existent plugin.
with self.assertRaises(SystemError):
with self.assertRaises(ValueError):
plugin_manager.stop_plugin(plugin_id="bogus")

def test_only_include_plugins_whose_ids_are_in_the_include_list(self):
Expand Down
2 changes: 1 addition & 1 deletion envisage/tests/test_provider_extension_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ def test_set_extensions(self):
registry.add_extension_point(self.create_extension_point("my.ep"))

# Set some extensions.
with self.assertRaises(SystemError):
with self.assertRaises(TypeError):
registry.set_extensions("my.ep", [1, 2, 3])

def test_remove_non_empty_extension_point(self):
Expand Down
4 changes: 2 additions & 2 deletions envisage/tests/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# Enthought library imports.
from envisage.api import Application, Plugin, Service
from traits.api import HasTraits, Instance
from traits.api import HasTraits, Instance, TraitError


class TestApplication(Application):
Expand Down Expand Up @@ -56,7 +56,7 @@ class PluginB(Plugin):
self.assertEqual(None, b.foo)

# You can't set service traits!
with self.assertRaises(SystemError):
with self.assertRaises(TraitError):
setattr(b, "foo", "bogus")

def test_service_trait_type_with_no_service_registry(self):
Expand Down
2 changes: 1 addition & 1 deletion examples/legacy/MOTD_Using_Eggs/dist/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def main():

distributions, errors = working_set.find_plugins(environment)
if len(errors) > 0:
raise SystemError('cannot add eggs %s' % errors)
raise RuntimeError('cannot add eggs %s' % errors)

logger.debug('added eggs %s' % distributions)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def create_control(self, parent):

method = getattr(self, "_%s_create_control" % ETSConfig.toolkit, None)
if method is None:
raise SystemError("Unknown toolkit %s", ETSConfig.toolkit)
raise RuntimeError("Unknown toolkit %s", ETSConfig.toolkit)

color = self.name.lower()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def main():

distributions, errors = working_set.find_plugins(environment)
if len(errors) > 0:
raise SystemError('cannot add eggs %s' % errors)
raise RuntimeError('cannot add eggs %s' % errors)

logger.debug('added eggs %s' % distributions)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def create_control(self, parent):

method = getattr(self, "_%s_create_control" % ETSConfig.toolkit, None)
if method is None:
raise SystemError("Unknown toolkit %s", ETSConfig.toolkit)
raise RuntimeError("Unknown toolkit %s", ETSConfig.toolkit)

color = self.name.lower()

Expand Down

0 comments on commit 886381e

Please sign in to comment.