Skip to content

Refactor error handling and add output control flags#13

Merged
smorin merged 7 commits intomainfrom
claude/codebase-improvement-recommendations-GSXaf
Mar 11, 2026
Merged

Refactor error handling and add output control flags#13
smorin merged 7 commits intomainfrom
claude/codebase-improvement-recommendations-GSXaf

Conversation

@smorin
Copy link
Copy Markdown
Contributor

@smorin smorin commented Mar 11, 2026

Summary

This PR refactors the codebase to use exception-based error handling instead of sys.exit() calls, introduces --quiet and --verbose output control flags, and migrates configuration to an instance-based RepoSettings dataclass for better testability and composability.

Key Changes

Error Handling Refactor

  • Created new WorktreeFlowError exception class as the base exception for business logic errors
  • Replaced all sys.exit(1) calls throughout manager.py with raise WorktreeFlowError()
  • Added _handle_error decorator in CLI layer to catch WorktreeFlowError and exit cleanly
  • Errors are now raised from business logic and handled at the CLI boundary, improving testability

Output Control

  • Added --quiet (-q) and --verbose (-v) flags to the main CLI command
  • Implemented three output methods in GitWorkflowManager:
    • info(): Prints informational messages (suppressed in quiet mode)
    • detail(): Prints verbose details (only shown in verbose mode)
    • error(): Always prints errors, even in quiet mode
  • Replaced direct console.print() calls with appropriate output methods throughout the manager
  • Added validation to prevent using --quiet and --verbose together

Configuration Refactoring

  • Created new RepoSettings dataclass to replace class-level RepoConfig mutation
  • load_config() now returns a RepoSettings instance instead of mutating class attributes
  • Maintained backward compatibility by updating RepoConfig class attributes for legacy code
  • Added self.config: RepoSettings instance to GitWorkflowManager
  • New _make_branch_name() method uses configured feature_branch_prefix

Code Quality Improvements

  • Reorganized imports (alphabetical ordering, grouped by type)
  • Fixed type hints (added Any import where needed)
  • Improved error messages with better formatting and context
  • Changed IOError to OSError (modern Python convention)
  • Removed unused subprocess import
  • Fixed bare repository detection with proper null check

Testing

  • Added comprehensive test suite for error handling (test_error_handling.py)
  • Added tests for configurable branch prefixes (test_configurable_prefix.py)
  • Added tests for quiet/verbose modes (test_quiet_verbose.py)
  • Updated existing tests to use RepoSettings and handle new exception patterns

Build Configuration

  • Replaced mypy with ty type checker in pyproject.toml and CI workflow
  • Updated dev dependencies accordingly

Notable Implementation Details

  • The GitWorkflowManager.__init__() now accepts quiet and verbose parameters
  • All output is now routed through the manager's output methods, enabling consistent behavior across quiet/verbose modes
  • RepoSettings is immutable and can be safely passed around without global side effects
  • The error handling pattern allows CLI to catch and format errors consistently
  • Backward compatibility maintained through RepoConfig class attribute updates

https://claude.ai/code/session_01Xi2i1GMmTRwCv3KZV5qs9T

claude added 3 commits March 11, 2026 05:41
…x, quiet/verbose, tests

- Add WorktreeFlowError exception class replacing sys.exit(1) in business logic,
  caught at CLI layer for clean error handling and testability
- Convert RepoConfig to instance-based RepoSettings dataclass, eliminating
  global mutable state while maintaining backward compatibility
- Replace all hardcoded "feat/" branch prefixes with configurable
  self._make_branch_name() using config.feature_branch_prefix
- Add --quiet/-q and --verbose/-v CLI flags with info()/detail()/error()
  output methods for scripting and CI integration
- Add 36 new tests covering error paths, quiet/verbose modes, configurable
  prefix, and complex operations (128 total, up from 92)
- Fix all ruff lint issues and reduce mypy errors from 30 to 26

https://claude.ai/code/session_01Xi2i1GMmTRwCv3KZV5qs9T
Switch from mypy to Astral's ty for type checking. Update pyproject.toml
dependency and configuration, CI workflow, and fix type errors caught by ty
(use functools.wraps, handle None working_tree_dir, fix delete_remote arg).

https://claude.ai/code/session_01Xi2i1GMmTRwCv3KZV5qs9T
Use collections.abc.Callable instead of typing.Callable, remove
version check for Python < 3.11, remove unused pytest import.

https://claude.ai/code/session_01Xi2i1GMmTRwCv3KZV5qs9T
@smorin smorin force-pushed the claude/codebase-improvement-recommendations-GSXaf branch from e5aa96d to 5761144 Compare March 11, 2026 05:43
claude added 4 commits March 11, 2026 05:53
Apply ruff format to 7 files that failed the format check in CI.

https://claude.ai/code/session_01Xi2i1GMmTRwCv3KZV5qs9T
Guard against empty stdout from `gh pr list` before attempting JSON
parse. Previously, empty string passed the `!= "[]"` check, causing
json.decoder.JSONDecodeError.

https://claude.ai/code/session_01Xi2i1GMmTRwCv3KZV5qs9T
Extract stdout to a local variable to stay under 120-char line limit
and properly guard against empty gh pr list output.

https://claude.ai/code/session_01Xi2i1GMmTRwCv3KZV5qs9T
Wrap json.loads in try/except to handle cases where gh pr list
returns non-JSON stdout (e.g. when mocked or on unexpected output).

https://claude.ai/code/session_01Xi2i1GMmTRwCv3KZV5qs9T
@smorin smorin merged commit fd73bfe into main Mar 11, 2026
5 checks passed
@smorin smorin deleted the claude/codebase-improvement-recommendations-GSXaf branch March 11, 2026 06:11
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.

2 participants