@@ -148,6 +148,12 @@ class SecureBootNotSupportedError(SecureBootError):
148
148
pass
149
149
150
150
151
+ class SecureBootConfigurationError (SecureBootError ):
152
+ """Exception raised when there's a configuration error."""
153
+
154
+ pass
155
+
156
+
151
157
class UbuntuVariant (Enum ):
152
158
"""Enumeration of Ubuntu variants."""
153
159
@@ -810,8 +816,10 @@ def create_checker(method: CheckerType) -> Tuple[SecureBootChecker, str]:
810
816
Tuple of (checker_instance, checker_name)
811
817
812
818
Raises:
813
- ValueError: If method is not one of the valid options
814
- RuntimeError: If no supported secure boot method is found
819
+ SecureBootConfigurationError: If method is not one of the valid
820
+ options
821
+ SecureBootNotSupportedError: If no supported secure boot method is
822
+ found
815
823
"""
816
824
# Define available checkers with their support checks and names
817
825
checkers = [
@@ -827,7 +835,7 @@ def create_checker(method: CheckerType) -> Tuple[SecureBootChecker, str]:
827
835
return checker , checker_name
828
836
829
837
# No supported method found
830
- raise RuntimeError (
838
+ raise SecureBootNotSupportedError (
831
839
"No supported secure boot method found. "
832
840
"Neither UEFI (mokutil) nor FIT (dumpimage) are available."
833
841
)
@@ -846,16 +854,18 @@ def create_checker(method: CheckerType) -> Tuple[SecureBootChecker, str]:
846
854
"system (dumpimage command not found)"
847
855
),
848
856
}
849
- raise RuntimeError (error_messages [method ])
857
+ raise SecureBootNotSupportedError (error_messages [method ])
850
858
checker = checker_class ()
851
859
return checker , checker_name
852
860
853
861
# This should never happen due to argument validation
854
- raise ValueError ("Unknown method: {}" .format (method .value ))
862
+ raise SecureBootConfigurationError (
863
+ "Unknown method: {}" .format (method .value )
864
+ )
855
865
856
866
857
- def main () -> None :
858
- """Main entry point for the secure boot state checker ."""
867
+ def create_parser () -> argparse . ArgumentParser :
868
+ """Create and configure the argument parser ."""
859
869
parser = argparse .ArgumentParser (
860
870
description = "Check and validate secure boot state" ,
861
871
formatter_class = argparse .RawDescriptionHelpFormatter ,
@@ -891,6 +901,12 @@ def main() -> None:
891
901
),
892
902
)
893
903
904
+ return parser
905
+
906
+
907
+ def main () -> None :
908
+ """Main entry point for the secure boot state checker."""
909
+ parser = create_parser ()
894
910
args = parser .parse_args ()
895
911
896
912
# Setup logging
@@ -918,11 +934,11 @@ def main() -> None:
918
934
exit_code = check_secure_boot_result (state , error_msg , check_mode )
919
935
sys .exit (exit_code )
920
936
921
- except ValueError as e :
937
+ except SecureBootConfigurationError as e :
922
938
logger .error ("Configuration error: {}" .format (str (e )))
923
939
sys .exit (1 )
924
- except RuntimeError as e :
925
- logger .error ("Runtime error: {}" .format (str (e )))
940
+ except SecureBootNotSupportedError as e :
941
+ logger .error ("Not supported error: {}" .format (str (e )))
926
942
sys .exit (1 )
927
943
except KeyboardInterrupt :
928
944
logger .info ("Operation cancelled by user" )
0 commit comments