Class: Git::SystemCallGuard Private
- Inherits:
-
Object
- Object
- Git::SystemCallGuard
- Defined in:
- lib/git/system_call_guard.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Convert SystemCallError raised by the gem's own filesystem calls to Error
The gem promises to raise only ArgumentError or a subclass of Error.
Filesystem calls such as File.read, Dir.chdir, or Tempfile.create can
raise a bare SystemCallError (Errno::ENOENT, Errno::EACCES, and so on).
Wrapping those calls in SystemCallGuard.call keeps the promise: the SystemCallError is
re-raised as a Error with the original error available as cause.
Helpers that yield to caller-supplied blocks must not relabel errors raised
by the caller's own code. #unguarded marks that region so a
SystemCallError raised inside it propagates unchanged.
Class Method Summary collapse
-
.call(message) {|guard| ... } ⇒ Object
private
Run the block, converting any
SystemCallErrorit raises to Error.
Instance Method Summary collapse
-
#call(message) {|guard| ... } ⇒ Object
private
Run the block, converting any
SystemCallErrorit raises to Error. -
#unguarded { ... } ⇒ Object
private
Run the block with
SystemCallErrorconversion suspended.
Class Method Details
.call(message) {|guard| ... } ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Run the block, converting any SystemCallError it raises to Error
50 51 52 |
# File 'lib/git/system_call_guard.rb', line 50 def self.call(, &) new.call(, &) end |
Instance Method Details
#call(message) {|guard| ... } ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Run the block, converting any SystemCallError it raises to Error
68 69 70 71 72 73 74 |
# File 'lib/git/system_call_guard.rb', line 68 def call() yield self rescue SystemCallError => e raise if e.equal?(@unguarded_error) raise Git::Error, "#{}: #{e.}" end |
#unguarded { ... } ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Run the block with SystemCallError conversion suspended
If the block raises a SystemCallError, the enclosing #call re-raises
that same error unchanged. Any other SystemCallError reaching #call,
including one raised while unwinding from the block's error, is converted.
88 89 90 91 92 93 |
# File 'lib/git/system_call_guard.rb', line 88 def unguarded yield rescue SystemCallError => e @unguarded_error = e raise end |