From b3fc45af03b6fb642e446700fbc05704950b8139 Mon Sep 17 00:00:00 2001 From: Mads Kiilerich Date: Mar 03 2023 14:03:36 +0000 Subject: Fix crash on member_defaults[package.name] Fooling around with packaging sapling, I got: + /usr/bin/cargo2rpm --path Cargo.toml buildrequires Traceback (most recent call last): File "/usr/bin/cargo2rpm", line 8, in sys.exit(main()) ^^^^^^ File "/usr/lib/python3.11/site-packages/cargo2rpm/__main__.py", line 99, in main action_buildrequires(args) File "/usr/lib/python3.11/site-packages/cargo2rpm/__main__.py", line 50, in action_buildrequires brs = workspace_buildrequires(metadata, flags, args.with_check) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/site-packages/cargo2rpm/rpm.py", line 221, in workspace_buildrequires member_flags = metadata.get_feature_flags_for_workspace_members(flags) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/site-packages/cargo2rpm/metadata.py", line 642, in get_feature_flags_for_workspace_members if member_defaults[package.name] and "default" in package.get_feature_names(): ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^ KeyError: 'backingstore' I don't know how special the case is that triggers this problem, but no amount of garbage input should be able to make the tool crash. It seems like a case that could be handled. This could be resolved by never using indexing when looking up in member_defaults, but always use .get() . There would thus not be any need for initializing it to False, neither with nor without flags.no_default_features . But it seems like it would be more close to the intention to unconditionally initialize it to False for all packages. This change fixes the crash, but I am not sure it tool does the right thing, or if the crash indicates a TODO situation. --- diff --git a/cargo2rpm/metadata.py b/cargo2rpm/metadata.py index c250156..5c836d7 100644 --- a/cargo2rpm/metadata.py +++ b/cargo2rpm/metadata.py @@ -602,8 +602,7 @@ class Metadata: features.add(feature) member_features[package.name] = features - if flags.no_default_features: - member_defaults[package.name] = False + member_defaults[package.name] = False # ensure that the mapping includes data for all packages features = member_features.get(package.name) or set()