-
Notifications
You must be signed in to change notification settings - Fork 5
🧹 Refactor exception handling in manifest-merge to use OSError #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -87,15 +87,15 @@ 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): | ||||||
| die(5, f"payload file not found: {payload_arg}") | ||||||
| try: | ||||||
| with open(payload_arg, "r", encoding="utf-8") as handle: | ||||||
| text = handle.read() | ||||||
| except Exception as exc: | ||||||
| except OSError as exc: | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since
Suggested change
|
||||||
| 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: | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since
Suggested change
|
||||||
| 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: | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
sys.stdin.read()can raise aUnicodeDecodeErrorif the input stream contains invalid UTF-8 bytes, catching onlyOSErrorwill allowUnicodeDecodeError(which inherits fromValueError) to propagate uncaught. This would cause the script to crash with a traceback instead of exiting gracefully viadie(). Consider catching bothOSErrorandUnicodeDecodeError.