class Git::SystemCallGuard

Convert ‘SystemCallError` raised by the gem’s own filesystem calls to {Git::Error}

The gem promises to raise only ‘ArgumentError` or a subclass of {Git::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 {.call} keeps the promise: the `SystemCallError` is re-raised as a {Git::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.

@example Guard a single filesystem call

content = Git::SystemCallGuard.call('Failed to read the gitdir pointer file') do
  File.read(path)
end

@example Guard setup and cleanup but not the caller’s block

def with_tempfile(&block)
  Git::SystemCallGuard.call('Failed to create a temporary file') do |guard|
    Tempfile.create do |file|
      guard.unguarded { block.call(file) }
    end
  end
end

@api private