Skip to content

fix: narrow bare except Exception in VS Code settings merge - #3844

Merged
mnriem merged 2 commits into
github:mainfrom
Quratulain-bilal:fix/utils-narrow-exception
Aug 13, 2026
Merged

fix: narrow bare except Exception in VS Code settings merge#3844
mnriem merged 2 commits into
github:mainfrom
Quratulain-bilal:fix/utils-narrow-exception

Conversation

@Quratulain-bilal

Copy link
Copy Markdown
Contributor

Summary

Narrow bare except Exception to specific exception types to let programming errors propagate.

Changes

  • _utils.py: Replace except Exception with (OSError, ValueError, KeyError)

Replace overly broad except Exception with (OSError, ValueError, KeyError)
to let programming errors like TypeError or AttributeError propagate while
still handling expected I/O and parse errors gracefully.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Narrows VS Code settings merge error handling so unexpected failures propagate.

Changes:

  • Replaces broad exception handling with selected exception types.
Show a summary per file
File Description
src/specify_cli/_utils.py Narrows settings merge exception handling.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comments suppressed due to low confidence (1)

src/specify_cli/_utils.py:216

  • KeyError is still a programming-error class, and no operation on this path uses an unchecked dictionary lookup: JSON5 parse failures are ValueError, filesystem operations raise OSError, and merge_json_files guards membership before indexing. Catching KeyError therefore still suppresses the kind of unexpected defect the PR says should propagate; limit this handler to the expected I/O and parse failures.
    except (OSError, ValueError, KeyError) as e:
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Medium

Comment thread src/specify_cli/_utils.py
The narrow exception change from 'except Exception' to
'except (OSError, ValueError, KeyError)' was not covered by a
regression test. Add a test that monkeypatches merge_json_files to
raise TypeError and verifies it propagates rather than being swallowed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review details

Suppressed comments (1)

src/specify_cli/_utils.py:216

  • This does not fully provide the promised programming-error propagation. KeyError is still swallowed here even though none of the expected file/JSON failure paths raises it, and merge_json_files() still catches every Exception while loading the existing settings (line 252), so a TypeError from that part of the merge is still converted to None. Remove KeyError from this handler and narrow the inner handler to the expected I/O/parse exceptions as well; the new test should exercise that real inner path rather than replacing the whole helper.
    except (OSError, ValueError, KeyError) as e:
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@mnriem
mnriem merged commit 16f4577 into github:main Aug 13, 2026
14 checks passed
@mnriem

mnriem commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants