Skip to content

Commit 1b08eef

Browse files
authored
Revert "Refactor the Error heriarchy (#693)"
This reverts commit 59a82a5.
1 parent 8da29c6 commit 1b08eef

13 files changed

+98
-258
lines changed

.github/workflows/continuous_integration.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
fail-fast: false
1919
matrix:
2020
# Only the latest versions of JRuby and TruffleRuby are tested
21-
ruby: ["3.0", "3.1", "3.2", "3.3", "truffleruby-24.0.0", "jruby-9.4.5.0"]
21+
ruby: ["3.0", "3.1", "3.2", "3.3", "truffleruby-23.1.1", "jruby-9.4.5.0"]
2222
operating-system: [ubuntu-latest]
2323
experimental: [No]
2424
include:
@@ -38,7 +38,7 @@ jobs:
3838

3939
steps:
4040
- name: Checkout Code
41-
uses: actions/checkout@v4
41+
uses: actions/checkout@v3
4242

4343
- name: Setup Ruby
4444
uses: ruby/setup-ruby@v1

README.md

Lines changed: 5 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -90,65 +90,11 @@ Pass the `--all` option to `git log` as follows:
9090

9191
**Git::Worktrees** - Enumerable object that holds `Git::Worktree objects`.
9292

93-
## Errors Raised By This Gem
94-
95-
This gem raises custom errors that derive from `Git::Error`. These errors are
96-
arranged in the following class heirarchy:
97-
98-
Error heirarchy:
99-
100-
```text
101-
Error
102-
└── CommandLineError
103-
├── FailedError
104-
└── SignaledError
105-
└── TimeoutError
106-
```
107-
108-
Other standard errors may also be raised like `ArgumentError`. Each method should
109-
document the errors it may raise.
110-
111-
Description of each Error class:
112-
113-
* `Error`: This catch-all error serves as the base class for other custom errors in this
114-
gem. Errors of this class are raised when no more approriate specific error to
115-
raise.
116-
* `CommandLineError`: This error is raised when there's a problem executing the git
117-
command line. This gem will raise a more specific error depending on how the
118-
command line failed.
119-
* `FailedError`: This error is raised when the git command line exits with a non-zero
120-
status code that is not expected by the git gem.
121-
* `SignaledError`: This error is raised when the git command line is terminated as a
122-
result of receiving a signal. This could happen if the process is forcibly
123-
terminated or if there is a serious system error.
124-
* `TimeoutError`: This is a specific type of `SignaledError` that is raised when the
125-
git command line operation times out and is killed via the SIGKILL signal. This
126-
happens if the operation takes longer than the timeout duration configured in
127-
`Git.config.timeout` or via the `:timeout` parameter given in git methods that
128-
support this parameter.
129-
130-
`Git::GitExecuteError` remains as an alias for `Git::Error`. It is considered
131-
deprecated as of git-2.0.0.
132-
133-
Here is an example of catching errors when using the git gem:
134-
135-
```ruby
136-
begin
137-
timeout_duration = 0.001 # seconds
138-
repo = Git.clone('https://github.com/ruby-git/ruby-git', 'ruby-git-temp', timeout: timeout_duration)
139-
rescue Git::TimeoutError => e # Catch the more specific error first!
140-
puts "Git clone took too long and timed out #{e}"
141-
rescue Git::Error => e
142-
puts "Received the following error: #{e}"
143-
end
144-
```
145-
14693
## Examples
14794

14895
Here are a bunch of examples of how to use the Ruby/Git package.
14996

15097
Require the 'git' gem.
151-
15298
```ruby
15399
require 'git'
154100
```
@@ -315,11 +261,11 @@ g.add(:all=>true) # git add --all -- "."
315261
g.add('file_path') # git add -- "file_path"
316262
g.add(['file_path_1', 'file_path_2']) # git add -- "file_path_1" "file_path_2"
317263

318-
g.remove() # git rm -f -- "."
319-
g.remove('file.txt') # git rm -f -- "file.txt"
320-
g.remove(['file.txt', 'file2.txt']) # git rm -f -- "file.txt" "file2.txt"
321-
g.remove('file.txt', :recursive => true) # git rm -f -r -- "file.txt"
322-
g.remove('file.txt', :cached => true) # git rm -f --cached -- "file.txt"
264+
g.remove() # git rm -f -- "."
265+
g.remove('file.txt') # git rm -f -- "file.txt"
266+
g.remove(['file.txt', 'file2.txt']) # git rm -f -- "file.txt" "file2.txt"
267+
g.remove('file.txt', :recursive => true) # git rm -f -r -- "file.txt"
268+
g.remove('file.txt', :cached => true) # git rm -f --cached -- "file.txt"
323269

324270
g.commit('message')
325271
g.commit_all('message')

lib/git.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
require 'git/signaled_error'
2828
require 'git/stash'
2929
require 'git/stashes'
30-
require 'git/timeout_error'
3130
require 'git/url'
3231
require 'git/version'
3332
require 'git/working_directory'

lib/git/command_line_error.rb

Lines changed: 0 additions & 59 deletions
This file was deleted.

lib/git/error.rb

Lines changed: 0 additions & 7 deletions
This file was deleted.

lib/git/failed_error.rb

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,51 @@
11
# frozen_string_literal: true
22

3-
require_relative 'command_line_error'
3+
require 'git/git_execute_error'
44

55
module Git
6-
# This error is raised when a git command returns a non-zero exitstatus
6+
# This error is raised when a git command fails
77
#
88
# The git command executed, status, stdout, and stderr are available from this
9-
# object.
9+
# object. The #message includes the git command, the status of the process, and
10+
# the stderr of the process.
1011
#
1112
# @api public
1213
#
13-
class FailedError < Git::CommandLineError; end
14+
class FailedError < Git::GitExecuteError
15+
# Create a FailedError object
16+
#
17+
# @example
18+
# `exit 1` # set $? appropriately for this example
19+
# result = Git::CommandLineResult.new(%w[git status], $?, 'stdout', 'stderr')
20+
# error = Git::FailedError.new(result)
21+
# error.message #=>
22+
# "[\"git\", \"status\"]\nstatus: pid 89784 exit 1\nstderr: \"stderr\""
23+
#
24+
# @param result [Git::CommandLineResult] the result of the git command including
25+
# the git command, status, stdout, and stderr
26+
#
27+
def initialize(result)
28+
super("#{result.git_cmd}\nstatus: #{result.status}\nstderr: #{result.stderr.inspect}")
29+
@result = result
30+
end
31+
32+
# @attribute [r] result
33+
#
34+
# The result of the git command including the git command and its status and output
35+
#
36+
# @example
37+
# `exit 1` # set $? appropriately for this example
38+
# result = Git::CommandLineResult.new(%w[git status], $?, 'stdout', 'stderr')
39+
# error = Git::FailedError.new(result)
40+
# error.result #=>
41+
# #<Git::CommandLineResult:0x00000001046bd488
42+
# @git_cmd=["git", "status"],
43+
# @status=#<Process::Status: pid 89784 exit 1>,
44+
# @stderr="stderr",
45+
# @stdout="stdout">
46+
#
47+
# @return [Git::CommandLineResult]
48+
#
49+
attr_reader :result
50+
end
1451
end

lib/git/git_execute_error.rb

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
# frozen_string_literal: true
22

3-
require_relative 'error'
4-
53
module Git
64
# This error is raised when a git command fails
75
#
8-
# This error class is used as an alias for Git::Error for backwards compatibility.
9-
# It is recommended to use Git::Error directly.
10-
#
11-
# @deprecated Use Git::Error instead
12-
#
13-
GitExecuteError = Git::Error
6+
class GitExecuteError < StandardError; end
147
end

lib/git/signaled_error.rb

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,50 @@
11
# frozen_string_literal: true
22

3-
require_relative 'command_line_error'
3+
require 'git/git_execute_error'
44

55
module Git
66
# This error is raised when a git command exits because of an uncaught signal
77
#
88
# The git command executed, status, stdout, and stderr are available from this
9-
# object.
9+
# object. The #message includes the git command, the status of the process, and
10+
# the stderr of the process.
1011
#
1112
# @api public
1213
#
13-
class SignaledError < Git::CommandLineError; end
14+
class SignaledError < Git::GitExecuteError
15+
# Create a SignaledError object
16+
#
17+
# @example
18+
# `kill -9 $$` # set $? appropriately for this example
19+
# result = Git::CommandLineResult.new(%w[git status], $?, '', "killed")
20+
# error = Git::SignaledError.new(result)
21+
# error.message #=>
22+
# "[\"git\", \"status\"]\nstatus: pid 88811 SIGKILL (signal 9)\nstderr: \"killed\""
23+
#
24+
# @param result [Git::CommandLineResult] the result of the git command including the git command, status, stdout, and stderr
25+
#
26+
def initialize(result)
27+
super("#{result.git_cmd}\nstatus: #{result.status}\nstderr: #{result.stderr.inspect}")
28+
@result = result
29+
end
30+
31+
# @attribute [r] result
32+
#
33+
# The result of the git command including the git command, status, and output
34+
#
35+
# @example
36+
# `kill -9 $$` # set $? appropriately for this example
37+
# result = Git::CommandLineResult.new(%w[git status], $?, '', "killed")
38+
# error = Git::SignaledError.new(result)
39+
# error.result #=>
40+
# #<Git::CommandLineResult:0x000000010470f6e8
41+
# @git_cmd=["git", "status"],
42+
# @status=#<Process::Status: pid 88811 SIGKILL (signal 9)>,
43+
# @stderr="killed",
44+
# @stdout="">
45+
#
46+
# @return [Git::CommandLineResult]
47+
#
48+
attr_reader :result
49+
end
1450
end

lib/git/timeout_error.rb

Lines changed: 0 additions & 60 deletions
This file was deleted.

tests/units/test_command_line_error.rb

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)