From eda695b6cda61a5f1901479b6a0b22d8ba1ed96b Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Wed, 9 Jan 2019 15:20:27 +0000 Subject: [PATCH] bootloader: raise LookupError on unknown BLS keys When loading a BootEntry from file, if an unknown BLS key is read a generic KeyError is raised when attempting to access a key in the MAP_KEY (bls-to-boom key name map) dictionary. This leads to a fairly cryptic error message: # boom list -V --debug all INFO - Could not load BootEntry '/boot/loader/entries/611f38fd887d41dea7eb3403b2730a76-4.15.17-200.fc26.x86_64.conf': 'id' With --debug=all the cause is a little more obvious: # boom list --debug all Traceback (most recent call last): File "bin/boom", line 7, in main(sys.argv) File "/home/breeves/src/git/boom/boom/command.py", line 1951, in main status = command[1](cmd_args, select, opts, identifier) File "/home/breeves/src/git/boom/boom/command.py", line 1287, in _list_cmd opts=opts, sort_keys=cmd_args.sort) File "/home/breeves/src/git/boom/boom/command.py", line 631, in print_entries bes = find_entries(selection=selection) File "/home/breeves/src/git/boom/boom/bootloader.py", line 769, in find_entries load_entries() File "/home/breeves/src/git/boom/boom/bootloader.py", line 659, in load_entries _add_entry(BootEntry(entry_file=entry_path)) File "/home/breeves/src/git/boom/boom/bootloader.py", line 1310, in __init__ return self.__from_file(entry_file, boot_params) File "/home/breeves/src/git/boom/boom/bootloader.py", line 1229, in __from_file key = MAP_KEY[_transform_key(bls_key)] KeyError: 'id' Instead, raise the exception explicitly if the key is not present, and set the exception string to a meaningful error: INFO - Could not load BootEntry '/boot/loader/entries/611f38fd887d41dea7eb3403b2730a76-4.15.17-200.fc26.x86_64.conf': Unknown BLS key 'id' The more specific KeyError is not used here since it is specific to dictionary lookup failures. Signed-off-by: Bryn M. Reeves (cherry picked from commit 72a67d8beba4c4f36d1c0682a6628b2a823041a4) Conflicts: boom/bootloader.py --- boom/bootloader.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/boom/bootloader.py b/boom/bootloader.py index bc86cb8..dd2a53a 100644 --- a/boom/bootloader.py +++ b/boom/bootloader.py @@ -1067,6 +1067,10 @@ class BootEntry(object): comment += line if line else "" else: bls_key, value = _parse_name_value(line, separator=None) + # Convert BLS key name to Boom notation + key = _transform_key(bls_key) + if key not in MAP_KEY: + raise LookupError("Unknown BLS key '%s'" % bls_key) key = MAP_KEY[_transform_key(bls_key)] entry_data[key] = value if comment: -- 1.8.3.1