From 0ea3a3204539181c97c4f47354c23bfd9b01d2ed Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 6 Jun 2026 01:48:57 +0000 Subject: [PATCH] fix: Catch OSError instead of Exception for IO operations Narrowed the scope of exception handling in bin/idstack-manifest-merge. Replaced overly broad `except Exception:` blocks with `except OSError:` for file reading and atomic writing. This improves maintainability and prevents masking of unrelated bugs. Co-authored-by: savvides <1580637+savvides@users.noreply.github.com> --- bin/idstack-manifest-merge | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/idstack-manifest-merge b/bin/idstack-manifest-merge index a799825..285b1c3 100755 --- a/bin/idstack-manifest-merge +++ b/bin/idstack-manifest-merge @@ -87,7 +87,7 @@ def load_payload(payload_arg): if payload_arg == "-": try: text = sys.stdin.read() - except Exception as exc: + except OSError as exc: die(6, f"failed to read payload from stdin: {exc}") else: if not os.path.isfile(payload_arg): @@ -95,7 +95,7 @@ def load_payload(payload_arg): try: with open(payload_arg, "r", encoding="utf-8") as handle: text = handle.read() - except Exception as exc: + except OSError as exc: die(6, f"failed to read payload file {payload_arg!r}: {exc}") try: return json.loads(text) @@ -109,7 +109,7 @@ def load_manifest(manifest_path): try: with open(manifest_path, "r", encoding="utf-8") as handle: text = handle.read() - except Exception as exc: + except OSError as exc: die(6, f"failed to read manifest {manifest_path!r}: {exc}") try: data = json.loads(text) @@ -130,7 +130,7 @@ def write_atomic(manifest_path, data): json.dump(data, handle, indent=2) handle.write("\n") os.replace(tmp_path, manifest_path) - except Exception as exc: + except OSError as exc: try: os.unlink(tmp_path) except OSError: