Skip to content

Commit 4e0bc17

Browse files
committed
fix: log better error in get_distributions
Log a better error message when JSON de-serialization fails in `BuildEnvironment.get_distribution()` call. Do not fail when debug log call with installed distributions is failing. The error is not fatal. Signed-off-by: Christian Heimes <cheimes@redhat.com>
1 parent 2b93a1f commit 4e0bc17

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/fromager/build_environment.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,10 @@ def get_distributions(self) -> typing.Mapping[str, Version]:
237237
"json.dump({d.name: d.version for d in distributions()}, sys.stdout)",
238238
]
239239
result = self.run([str(self.python), "-c", "; ".join(lines)])
240-
mapping = json.loads(result.strip())
240+
try:
241+
mapping = json.loads(result.strip())
242+
except Exception:
243+
logger.exception("failed to de-serialize JSON: %s", result)
241244
return {name: Version(version) for name, version in sorted(mapping.items())}
242245

243246

@@ -296,9 +299,13 @@ def prepare_build_environment(
296299
dep_req_type=RequirementType.BUILD_SDIST,
297300
)
298301

299-
logger.debug(
300-
"build env %r has packages %r", build_env.path, build_env.get_distributions()
301-
)
302+
try:
303+
distributions = build_env.get_distributions()
304+
except Exception:
305+
# ignore error for debug call, error reason is logged in get_distributions()
306+
pass
307+
else:
308+
logger.debug("build env %r has packages %r", build_env.path, distributions)
302309

303310
return build_env
304311

0 commit comments

Comments
 (0)