From 0c54eaf1763149eedee7755ffe53058ca344a669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Sun, 28 Jun 2015 02:19:28 +0200 Subject: [PATCH] Fix: Use Exception, not BaseException Custom exception should be derived from Exception, not BaseException. Not only is this specified in the python documentation, but also tornado will be able to handle Exceptions in requests perfectly fine and return an HTTP 500 for them, but crash hard (as in, server shut down follows) for BaseExceptions. (cherry picked from commit 29b047b) --- src/octoprint/plugin/core.py | 8 ++++---- src/octoprint/printer/__init__.py | 2 +- src/octoprint/server/api/languages.py | 2 +- src/octoprint/slicing/exceptions.py | 6 +++--- src/octoprint/util/comm.py | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/octoprint/plugin/core.py b/src/octoprint/plugin/core.py index 8a505372..913289de 100644 --- a/src/octoprint/plugin/core.py +++ b/src/octoprint/plugin/core.py @@ -1213,15 +1213,15 @@ class Plugin(object): class RestartNeedingPlugin(Plugin): pass -class PluginNeedsRestart(BaseException): +class PluginNeedsRestart(Exception): def __init__(self, name): - BaseException.__init__(self) + Exception.__init__(self) self.name = name self.message = "Plugin {name} cannot be enabled or disabled after system startup".format(**locals()) -class PluginLifecycleException(BaseException): +class PluginLifecycleException(Exception): def __init__(self, name, reason, message): - BaseException.__init__(self) + Exception.__init__(self) self.name = name self.reason = reason diff --git a/src/octoprint/printer/__init__.py b/src/octoprint/printer/__init__.py index e0989a93..0a4195da 100644 --- a/src/octoprint/printer/__init__.py +++ b/src/octoprint/printer/__init__.py @@ -467,6 +467,6 @@ class PrinterCallback(object): """ pass -class UnknownScript(BaseException): +class UnknownScript(Exception): def __init__(self, name, *args, **kwargs): self.name = name diff --git a/src/octoprint/server/api/languages.py b/src/octoprint/server/api/languages.py index a3690f74..820089e4 100644 --- a/src/octoprint/server/api/languages.py +++ b/src/octoprint/server/api/languages.py @@ -143,5 +143,5 @@ def _validate_archive_name(name): raise InvalidLanguagePack("Provided language pack contains invalid name {name}".format(**locals())) -class InvalidLanguagePack(BaseException): +class InvalidLanguagePack(Exception): pass diff --git a/src/octoprint/slicing/exceptions.py b/src/octoprint/slicing/exceptions.py index 4d789107..8a543e9f 100644 --- a/src/octoprint/slicing/exceptions.py +++ b/src/octoprint/slicing/exceptions.py @@ -33,7 +33,7 @@ __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agp __copyright__ = "Copyright (C) 2015 The OctoPrint Project - Released under terms of the AGPLv3 License" -class SlicingException(BaseException): +class SlicingException(Exception): """ Base exception of all slicing related exceptions. """ @@ -73,7 +73,7 @@ class UnknownSlicer(SlicerException): SlicerException.__init__(self, slicer, *args, **kwargs) self.message = "No such slicer: {slicer}".format(slicer=slicer) -class ProfileException(BaseException): +class ProfileException(Exception): """ Base exception of all slicing profile related exceptions. @@ -86,7 +86,7 @@ class ProfileException(BaseException): Identifier of the profile for which the exception was raised. """ def __init__(self, slicer, profile, *args, **kwargs): - BaseException.__init__(self, *args, **kwargs) + Exception.__init__(self, *args, **kwargs) self.slicer = slicer self.profile = profile diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 14ca4f59..65c99025 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -1982,9 +1982,9 @@ class TypedQueue(queue.Queue): return item -class TypeAlreadyInQueue(BaseException): +class TypeAlreadyInQueue(Exception): def __init__(self, t, *args, **kwargs): - BaseException.__init__(self, *args, **kwargs) + Exception.__init__(self, *args, **kwargs) self.type = t