Exception: Git::CommandLineError

Inherits:
Error
  • Object
show all
Defined in:
lib/git/errors.rb

Overview

Raised when a git command fails or exits because of an uncaught signal

The git command executed, status, stdout, and stderr are available from this object.

The Gem will raise a more specific error for each type of failure:

  • FailedError: when the git command exits with a non-zero status
  • SignaledError: when the git command exits because of an uncaught signal
  • TimeoutError: when the git command times out

Direct Known Subclasses

FailedError, SignaledError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result) ⇒ CommandLineError

Create a CommandLineError object

Examples:

`exit 1` # set $? appropriately for this example result = Git::CommandLineResult.new(%w[git status], $?, 'stdout', 'stderr') error = Git::CommandLineError.new(result) error.to_s #=> '["git", "status"], status: pid 89784 exit 1, stderr: "stderr"'

Parameters:

  • result (Git::CommandLineResult)

    the result of the git command including the git command, status, stdout, and stderr

 101 102 103 104
# File 'lib/git/errors.rb', line 101 def initialize(result) @result = result super(error_message) end

Instance Attribute Details

#resultGit::CommandLineResult (readonly)

The result of the git command including the git command and its status and output

Examples:

error.result #=> #<Git::CommandLineResult:0x00000001046bd488 ...>

Returns:

 126 127 128
# File 'lib/git/errors.rb', line 126 def result @result end

Instance Method Details

#error_messageString

The human readable representation of this error

Examples:

error.error_message #=> '["git", "status"], status: pid 89784 exit 1, stderr: "stderr"'

Returns:

  • (String)
 113 114 115
# File 'lib/git/errors.rb', line 113 def error_message = <<~MESSAGE.chomp  #{result.git_cmd}, status: #{result.status}, stderr: #{result.stderr.inspect} MESSAGE