Skip to content

Refactor error thrown when a git command fails #622

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

Merged
merged 1 commit into from
Feb 21, 2023

Conversation

jcouball
Copy link
Member

@jcouball jcouball commented Feb 21, 2023

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

In preparation for refactoring how Git commands are executed by this gem (see #617), add two new classes: Git::FailedError and Git::SignaledError to indicate different failure conditions when running the Git CLI.

  • Git::FailedError is raised when the git command returns a non-zero exitstatus.
  • Git::Signaled is raised when the git command fails because of an uncaught signal (like a kill signal).

Both of these new errors derive from Git::GitExecuteError so existing code that was rescuing this error will still work as before.

Both of these new errors expect to be initialized with an instance of another new class added in this PR: Git::CommandLineResult. Objects of this class capture:

  • the git command executed
  • the resulting Process::Status
  • the command's stdout
  • the command's stderr

The intent is to give callers better context as to the type of error (non-zero exitstatus vs. uncaught signal) as well as provide better context as to the command executed, the ending status of the process (including exitstatus or signal #), and the captured command line output.

Git::FailedError has been fully integrated into Git::Lib#command. Any situation where a Git::GitExecuteError would have been raised before now raises a Git::FailedError. As mentioned before, since Git::FailedError is a subclass of Git::GitExecuteError, no change is required to client code.

Git::SignaledError has not yet be integrated into Git::Lib#command.

Signed-off-by: James Couball <jcouball@yahoo.com>
@jcouball jcouball merged commit 8992701 into master Feb 21, 2023
@jcouball jcouball deleted the refactor_git_execute_error branch February 21, 2023 16:57
@jcouball jcouball mentioned this pull request Feb 26, 2023
# the git command, status, stdout, and stderr
#
def initialize(result)
super("#{result.git_cmd}\nstatus: #{result.status}\nstderr: #{result.stderr.inspect}")

Choose a reason for hiding this comment

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

@jcouball I think stdout also has to be printed here since stderr is redirected to stdout??

git_cmd = "#{Git::Base.config.binary_path} #{global_opts} #{escaped_cmd} #{redirect} 2>&1"

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