-
Notifications
You must be signed in to change notification settings - Fork 514
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor the Error heriarchy * Bump truffleruby to 24.0.0 to get support for endless methods Signed-off-by: James Couball <jcouball@yahoo.com>
- Loading branch information
Showing
13 changed files
with
258 additions
and
98 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'error' | ||
|
||
module Git | ||
# 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. | ||
# | ||
# Rather than creating a CommandLineError object directly, it is recommended to use | ||
# one of the derived classes for the appropriate type of error: | ||
# | ||
# * {Git::FailedError}: when the git command exits with a non-zero status | ||
# * {Git::SignaledError}: when the git command exits because of an uncaught signal | ||
# * {Git::TimeoutError}: when the git command times out | ||
# | ||
# @api public | ||
# | ||
class CommandLineError < Git::Error | ||
# Create a CommandLineError object | ||
# | ||
# @example | ||
# `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"' | ||
# | ||
# @param result [Git::CommandLineResult] the result of the git command including | ||
# the git command, status, stdout, and stderr | ||
# | ||
def initialize(result) | ||
@result = result | ||
super() | ||
end | ||
|
||
# The human readable representation of this error | ||
# | ||
# @example | ||
# error.to_s #=> '["git", "status"], status: pid 89784 exit 1, stderr: "stderr"' | ||
# | ||
# @return [String] | ||
# | ||
def to_s = <<~MESSAGE.chomp | ||
#{result.git_cmd}, status: #{result.status}, stderr: #{result.stderr.inspect} | ||
MESSAGE | ||
|
||
# @attribute [r] result | ||
# | ||
# The result of the git command including the git command and its status and output | ||
# | ||
# @example | ||
# error.result #=> #<Git::CommandLineResult:0x00000001046bd488 ...> | ||
# | ||
# @return [Git::CommandLineResult] | ||
# | ||
attr_reader :result | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
module Git | ||
# Base class for all custom git module errors | ||
# | ||
class Error < StandardError; end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'git/git_execute_error' | ||
require_relative 'command_line_error' | ||
|
||
module Git | ||
# This error is raised when a git command fails | ||
# This error is raised when a git command returns a non-zero exitstatus | ||
# | ||
# The git command executed, status, stdout, and stderr are available from this | ||
# object. The #message includes the git command, the status of the process, and | ||
# the stderr of the process. | ||
# object. | ||
# | ||
# @api public | ||
# | ||
class FailedError < Git::GitExecuteError | ||
# Create a FailedError object | ||
# | ||
# @example | ||
# `exit 1` # set $? appropriately for this example | ||
# result = Git::CommandLineResult.new(%w[git status], $?, 'stdout', 'stderr') | ||
# error = Git::FailedError.new(result) | ||
# error.message #=> | ||
# "[\"git\", \"status\"]\nstatus: pid 89784 exit 1\nstderr: \"stderr\"" | ||
# | ||
# @param result [Git::CommandLineResult] the result of the git command including | ||
# the git command, status, stdout, and stderr | ||
# | ||
def initialize(result) | ||
super("#{result.git_cmd}\nstatus: #{result.status}\nstderr: #{result.stderr.inspect}") | ||
@result = result | ||
end | ||
|
||
# @attribute [r] result | ||
# | ||
# The result of the git command including the git command and its status and output | ||
# | ||
# @example | ||
# `exit 1` # set $? appropriately for this example | ||
# result = Git::CommandLineResult.new(%w[git status], $?, 'stdout', 'stderr') | ||
# error = Git::FailedError.new(result) | ||
# error.result #=> | ||
# #<Git::CommandLineResult:0x00000001046bd488 | ||
# @git_cmd=["git", "status"], | ||
# @status=#<Process::Status: pid 89784 exit 1>, | ||
# @stderr="stderr", | ||
# @stdout="stdout"> | ||
# | ||
# @return [Git::CommandLineResult] | ||
# | ||
attr_reader :result | ||
end | ||
class FailedError < Git::CommandLineError; end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'error' | ||
|
||
module Git | ||
# This error is raised when a git command fails | ||
# | ||
class GitExecuteError < StandardError; end | ||
# This error class is used as an alias for Git::Error for backwards compatibility. | ||
# It is recommended to use Git::Error directly. | ||
# | ||
# @deprecated Use Git::Error instead | ||
# | ||
GitExecuteError = Git::Error | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'git/git_execute_error' | ||
require_relative 'command_line_error' | ||
|
||
module Git | ||
# This error is raised when a git command exits because of an uncaught signal | ||
# | ||
# The git command executed, status, stdout, and stderr are available from this | ||
# object. The #message includes the git command, the status of the process, and | ||
# the stderr of the process. | ||
# object. | ||
# | ||
# @api public | ||
# | ||
class SignaledError < Git::GitExecuteError | ||
# Create a SignaledError object | ||
# | ||
# @example | ||
# `kill -9 $$` # set $? appropriately for this example | ||
# result = Git::CommandLineResult.new(%w[git status], $?, '', "killed") | ||
# error = Git::SignaledError.new(result) | ||
# error.message #=> | ||
# "[\"git\", \"status\"]\nstatus: pid 88811 SIGKILL (signal 9)\nstderr: \"killed\"" | ||
# | ||
# @param result [Git::CommandLineResult] the result of the git command including the git command, status, stdout, and stderr | ||
# | ||
def initialize(result) | ||
super("#{result.git_cmd}\nstatus: #{result.status}\nstderr: #{result.stderr.inspect}") | ||
@result = result | ||
end | ||
|
||
# @attribute [r] result | ||
# | ||
# The result of the git command including the git command, status, and output | ||
# | ||
# @example | ||
# `kill -9 $$` # set $? appropriately for this example | ||
# result = Git::CommandLineResult.new(%w[git status], $?, '', "killed") | ||
# error = Git::SignaledError.new(result) | ||
# error.result #=> | ||
# #<Git::CommandLineResult:0x000000010470f6e8 | ||
# @git_cmd=["git", "status"], | ||
# @status=#<Process::Status: pid 88811 SIGKILL (signal 9)>, | ||
# @stderr="killed", | ||
# @stdout=""> | ||
# | ||
# @return [Git::CommandLineResult] | ||
# | ||
attr_reader :result | ||
end | ||
class SignaledError < Git::CommandLineError; end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'signaled_error' | ||
|
||
module Git | ||
# This error is raised when a git command takes longer than the configured timeout | ||
# | ||
# The git command executed, status, stdout, and stderr, and the timeout duration | ||
# are available from this object. | ||
# | ||
# result.status.timeout? will be `true` | ||
# | ||
# @api public | ||
# | ||
class TimeoutError < Git::SignaledError | ||
# Create a TimeoutError object | ||
# | ||
# @example | ||
# command = %w[sleep 10] | ||
# timeout_duration = 1 | ||
# status = ProcessExecuter.spawn(*command, timeout: timeout_duration) | ||
# result = Git::CommandLineResult.new(command, status, 'stdout', 'err output') | ||
# error = Git::TimeoutError.new(result, timeout_duration) | ||
# error.to_s #=> '["sleep", "10"], status: pid 70144 SIGKILL (signal 9), stderr: "err output", timed out after 1s' | ||
# | ||
# @param result [Git::CommandLineResult] the result of the git command including | ||
# the git command, status, stdout, and stderr | ||
# | ||
# @param timeout_duration [Numeric] the amount of time the subprocess was allowed | ||
# to run before being killed | ||
# | ||
def initialize(result, timeout_duration) | ||
@timeout_duration = timeout_duration | ||
super(result) | ||
end | ||
|
||
# The human readable representation of this error | ||
# | ||
# @example | ||
# error.to_s #=> '["sleep", "10"], status: pid 88811 SIGKILL (signal 9), stderr: "err output", timed out after 1s' | ||
# | ||
# @return [String] | ||
# | ||
def to_s = <<~MESSAGE.chomp | ||
#{super}, timed out after #{timeout_duration}s | ||
MESSAGE | ||
|
||
# The amount of time the subprocess was allowed to run before being killed | ||
# | ||
# @example | ||
# `kill -9 $$` # set $? appropriately for this example | ||
# result = Git::CommandLineResult.new(%w[git status], $?, '', "killed") | ||
# error = Git::TimeoutError.new(result, 10) | ||
# error.timeout_duration #=> 10 | ||
# | ||
# @return [Numeric] | ||
# | ||
attr_reader :timeout_duration | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'test_helper' | ||
|
||
class TestCommandLineError < Test::Unit::TestCase | ||
def test_initializer | ||
status = Struct.new(:to_s).new('pid 89784 exit 1') | ||
result = Git::CommandLineResult.new(%w[git status], status, 'stdout', 'stderr') | ||
|
||
error = Git::CommandLineError.new(result) | ||
|
||
assert(error.is_a?(Git::Error)) | ||
assert_equal(result, error.result) | ||
end | ||
|
||
def test_to_s | ||
status = Struct.new(:to_s).new('pid 89784 exit 1') | ||
result = Git::CommandLineResult.new(%w[git status], status, 'stdout', 'stderr') | ||
|
||
error = Git::CommandLineError.new(result) | ||
|
||
expected_message = '["git", "status"], status: pid 89784 exit 1, stderr: "stderr"' | ||
assert_equal(expected_message, error.to_s) | ||
end | ||
end |
Oops, something went wrong.