From 46334ed7d4d20ad7e53226a4a1601693f5906243 Mon Sep 17 00:00:00 2001 From: Chris PeBenito Date: Thu, 7 May 2020 10:37:50 -0400 Subject: [PATCH] Default: Add better messages for unsupported default values. For #44 Signed-off-by: Chris PeBenito --- setools/policyrep/default.pxi | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/setools/policyrep/default.pxi b/setools/policyrep/default.pxi index e66eb29..10441ff 100644 --- a/setools/policyrep/default.pxi +++ b/setools/policyrep/default.pxi @@ -44,7 +44,10 @@ class DefaultValue(PolicyEnum): sepol.DEFAULT_TARGET_HIGH: sepol.DEFAULT_TARGET, sepol.DEFAULT_TARGET_LOW_HIGH: sepol.DEFAULT_TARGET} - return cls(default_map[range_]) + try: + return cls(default_map[range_]) + except KeyError as e: + raise LowLevelPolicyError("Unsupported default value: {}".format(e)) from e class DefaultRangeValue(PolicyEnum): @@ -64,7 +67,10 @@ class DefaultRangeValue(PolicyEnum): sepol.DEFAULT_TARGET_HIGH: 2, sepol.DEFAULT_TARGET_LOW_HIGH: 3} - return cls(default_map[range_]) + try: + return cls(default_map[range_]) + except KeyError as e: + raise LowLevelPolicyError("Unsupported default_range value: {}".format(e)) from e cdef class Default(PolicyObject):