class Git::Error

Base class for all custom git module errors

The git gem will only raise an โ€˜ArgumentError` or an error that is a subclass of `Git::Error`.

It is recommended to rescue โ€˜Git::Error` to catch any runtime error raised by this gem unless you need more specific error handling.

Operating system errors from the gemโ€™s own filesystem operations, such as reading a โ€˜.git` pointer file or creating a temporary file, are raised as `Git::Error`. The original `SystemCallError` is available through `cause`.

The promise covers errors the gem raises from its own operations. An error raised by a block your code passes to a method such as โ€˜chdir` propagates unchanged, and when `Git::Deprecation.behavior` is `:raise` a deprecated call raises `ActiveSupport::DeprecationException`, which is intentionally not a `Git::Error`.

Gitโ€™s custom errors are arranged in the following class heirarchy:

โ€œโ€˜text StandardError โ””โ”€> Git::Error

โ”œโ”€> Git::CommandLineError
โ”‚   โ”œโ”€> Git::FailedError
โ”‚   โ””โ”€> Git::SignaledError
โ”‚       โ””โ”€> Git::TimeoutError
โ”œโ”€> Git::ProcessIOError
โ”œโ”€> Git::UnexpectedResultError
โ””โ”€> Git::VersionError

โ€œโ€˜

| Error Class | Description | | โ€” | โ€” | | โ€˜Error` | This catch-all error serves as the base class for other custom errors raised by the git gem. | | `CommandLineError` | A subclass of this error is raised when there is a problem executing the git command line. | | `FailedError` | This error is raised when the git command line exits with a non-zero status code that is not expected by the git gem. | | `SignaledError` | This error is raised when the git command line is terminated as a result of receiving a signal. This could happen if the process is forcibly terminated or if there is a serious system error. | | `TimeoutError` | This is a specific type of `SignaledError` that is raised when the git command line operation times out and is killed via the SIGKILL signal. This happens if the operation takes longer than the timeout duration configured in `Git.config.timeout` or via the `:timeout` parameter given in git methods that support timeouts. | | `ProcessIOError` | An error was encountered reading or writing to a subprocess. | | `UnexpectedResultError` | The command line ran without error but did not return the expected results. | | `VersionError` | The installed git version does not meet the requirements of the git gem or a specific command. |

@example Rescuing a generic error

begin
  # some git operation
rescue Git::Error => e
  puts "An error occurred: #{e.message}"
end

@example Rescuing a timeout error

begin
  timeout_duration = 0.001 # seconds
  repo = Git.clone('https://github.com/ruby-git/ruby-git', 'ruby-git-temp', timeout: timeout_duration)
rescue Git::TimeoutError => e # Catch the more specific error first!
  puts "Git clone took too long and timed out #{e}"
rescue Git::Error => e
  puts "Received the following error: #{e}"
end

@see Git::CommandLineError

@see Git::FailedError

@see Git::SignaledError

@see Git::TimeoutError

@see Git::ProcessIOError

@see Git::UnexpectedResultError

@see Git::VersionError

@api public