From f97a6ebd74caddffbb890a1cf39f1168b33bb461 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Thu, 23 Mar 2017 17:49:16 +0100 Subject: [PATCH] Move exceptions to their own file Since that keeps the GlobalStack cleaner Contributes to CURA-3497 --- cura/Settings/Exceptions.py | 17 +++++++++++++++++ cura/Settings/GlobalStack.py | 5 ++--- 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 cura/Settings/Exceptions.py diff --git a/cura/Settings/Exceptions.py b/cura/Settings/Exceptions.py new file mode 100644 index 0000000000..846e740950 --- /dev/null +++ b/cura/Settings/Exceptions.py @@ -0,0 +1,17 @@ +# Copyright (c) 2017 Ultimaker B.V. +# Cura is released under the terms of the AGPLv3 or higher. + + +## Raised when trying to perform an operation like add on a stack that does not allow that. +class InvalidOperationError(Exception): + pass + + +## Raised when trying to replace a container with a container that does not have the expected type. +class InvalidContainerError(Exception): + pass + + +## Raised when trying to add an extruder to a Global stack that already has the maximum number of extruders. +class TooManyExtrudersError(Exception): + pass diff --git a/cura/Settings/GlobalStack.py b/cura/Settings/GlobalStack.py index 4d25293ead..622e013a0b 100644 --- a/cura/Settings/GlobalStack.py +++ b/cura/Settings/GlobalStack.py @@ -11,8 +11,7 @@ from UM.Settings.InstanceContainer import InstanceContainer from UM.Settings.DefinitionContainer import DefinitionContainer from UM.Settings.ContainerRegistry import ContainerRegistry -class CannotSetNextStackError(Exception): - pass +from . import Exceptions class GlobalStack(ContainerStack): def __init__(self, container_id: str, *args, **kwargs): @@ -78,7 +77,7 @@ class GlobalStack(ContainerStack): ## Overridden from ContainerStack @override(ContainerStack) def setNextStack(self, next_stack: ContainerStack) -> None: - raise CannotSetNextStackError("Global stack cannot have a next stack!") + raise Exceptions.InvalidOperationError("Global stack cannot have a next stack!") ## Overridden from ContainerStack @override(ContainerStack)