Refactor error handling and add output control flags#13
Merged
Conversation
…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
e5aa96d to
5761144
Compare
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR refactors the codebase to use exception-based error handling instead of
sys.exit()calls, introduces--quietand--verboseoutput control flags, and migrates configuration to an instance-basedRepoSettingsdataclass for better testability and composability.Key Changes
Error Handling Refactor
WorktreeFlowErrorexception class as the base exception for business logic errorssys.exit(1)calls throughoutmanager.pywithraise WorktreeFlowError()_handle_errordecorator in CLI layer to catchWorktreeFlowErrorand exit cleanlyOutput Control
--quiet(-q) and--verbose(-v) flags to the main CLI commandGitWorkflowManager:info(): Prints informational messages (suppressed in quiet mode)detail(): Prints verbose details (only shown in verbose mode)error(): Always prints errors, even in quiet modeconsole.print()calls with appropriate output methods throughout the manager--quietand--verbosetogetherConfiguration Refactoring
RepoSettingsdataclass to replace class-levelRepoConfigmutationload_config()now returns aRepoSettingsinstance instead of mutating class attributesRepoConfigclass attributes for legacy codeself.config: RepoSettingsinstance toGitWorkflowManager_make_branch_name()method uses configuredfeature_branch_prefixCode Quality Improvements
Anyimport where needed)IOErrortoOSError(modern Python convention)subprocessimportTesting
test_error_handling.py)test_configurable_prefix.py)test_quiet_verbose.py)RepoSettingsand handle new exception patternsBuild Configuration
tytype checker inpyproject.tomland CI workflowNotable Implementation Details
GitWorkflowManager.__init__()now acceptsquietandverboseparametersRepoSettingsis immutable and can be safely passed around without global side effectsRepoConfigclass attribute updateshttps://claude.ai/code/session_01Xi2i1GMmTRwCv3KZV5qs9T