Skip to content
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

Refactor the Error heriarchy #693

Merged
merged 2 commits into from
Feb 5, 2024
Merged

Refactor the Error heriarchy #693

merged 2 commits into from
Feb 5, 2024

Conversation

jcouball
Copy link
Member

@jcouball jcouball commented Feb 5, 2024

Your checklist for this pull request

🚨Please review the guidelines for contributing to this repository.

  • Ensure all commits include DCO sign-off.
  • Ensure that your contributions pass unit testing.
  • Ensure that your contributions contain documentation if applicable.

Description

This PR redesigns the custom errors defined by this gem. Here is a description of the new design from the updated README.md:

This gem raises custom errors that derive from Git::Error. These errors are
arranged in the following class heirarchy:

Error heirarchy:

Error
└── CommandLineError
    ├── FailedError
    └── SignaledError
        └── TimeoutError

Other standard errors may also be raised like ArgumentError. Each method should
document the errors it may raise.

Description of each Error class:

  • Error: This catch-all error serves as the base class for other custom errors in this
    gem. Errors of this class are raised when no more approriate specific error to
    raise.
  • CommandLineError: This error is raised when there's a problem executing the git
    command line. This gem will raise a more specific error depending on how the
    command line failed.
  • FailedError: This error is raised when the git command line exits with a non-zero
    status code that is not expected by the git gem.
  • SignaledError: This error is raised when the git command line is terminated as a
    result of receiving a signal. This could happen if the process is forcibly
    terminated or if there is a serious system error.
  • TimeoutError: This is a specific type of SignaledError that is raised when the
    git command line operation times out and is killed via the SIGKILL signal. This
    happens if the operation takes longer than the timeout duration configured in
    Git.config.timeout or via the :timeout parameter given in git methods that
    support this parameter.

Git::GitExecuteError remains as an alias for Git::Error. It is considered
deprecated as of git-2.0.0.

Here is an example of catching errors when using the git gem:

begin
  timeout_duration = 0.001 # seconds
  repo = Git.clone('https://github.com/ruby-git/ruby-git', 'ruby-git-temp', timeout: timeout_duration)
rescue Git::TimeoutError => e # Catch the more specific error first!
  puts "Git clone took too long and timed out #{e}"
rescue Git::Error => e
  puts "Received the following error: #{e}"
end

Signed-off-by: James Couball <jcouball@yahoo.com>
Signed-off-by: James Couball <jcouball@yahoo.com>
@jcouball jcouball merged commit 8286ceb into master Feb 5, 2024
8 of 10 checks passed
@jcouball jcouball deleted the refactor_errors branch February 5, 2024 16:36
@jcouball jcouball mentioned this pull request Feb 24, 2024
jcouball added a commit that referenced this pull request Mar 19, 2024
* Refactor the Error heriarchy
* Bump truffleruby to 24.0.0 to get support for endless methods

Signed-off-by: James Couball <jcouball@yahoo.com>
jcouball added a commit that referenced this pull request Mar 19, 2024
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.

None yet

1 participant