Skip to content

Commit 53a02e8

Browse files
committed
Change ValueError to a specific error
1 parent 9370807 commit 53a02e8

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

magicbot/magicrobot.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
__all__ = ['MagicRobot']
2020

21+
class MagicInjectError(ValueError):
22+
pass
23+
2124

2225
class MagicRobot(wpilib.SampleRobot,
2326
metaclass=OrderedClass):
@@ -529,7 +532,7 @@ def _setup_vars(self, cname, component):
529532
# If the value given to the variable is an instance of a type and isn't a property
530533
# raise an error. No double declaring types, e.g foo: type = type
531534
if isinstance(attr, type) and not isinstance(attr, property):
532-
raise ValueError("%s.%s has two type declarations" % (component_type.__name__, n))
535+
raise MagicInjectError("%s.%s has two type declarations" % (component_type.__name__, n))
533536
# Otherwise, skip this set class variable
534537
continue
535538

@@ -568,12 +571,12 @@ def _inject(self, n, inject_type, cname, component):
568571

569572
# Raise error if injectable syntax used but no injectable was found.
570573
if injectable is None:
571-
raise ValueError("Component %s has variable %s (type %s), which is not present in %s" %
574+
raise MagicInjectError("Component %s has variable %s (type %s), which is not present in %s" %
572575
(cname, n, inject_type, self))
573576

574577
# Raise error if injectable declared with type different than the initial type
575578
if not isinstance(injectable, inject_type):
576-
raise ValueError("Component %s variable %s in %s are not the same types! (Got %s, expected %s)" %
579+
raise MagicInjectError("Component %s variable %s in %s are not the same types! (Got %s, expected %s)" %
577580
(cname, n, self, type(injectable), inject_type))
578581
# Perform injection
579582
setattr(component, n, injectable)

0 commit comments

Comments
 (0)