Skip to content

Error Handling

All throwing functions in Gitty throw GittyError.

public struct GittyError: Error, Sendable {
public let message: String
public let code: Int32? // libgit2 error code, nil for logic errors
}
do {
let repo = try Repository.open(at: someURL)
} catch let error as GittyError {
print("Git error:", error.message)
if let code = error.code {
print("libgit2 code:", code)
}
}
ScenarioTypical message
Path is not a repository"could not find repository"
Branch already exists"a reference with that name already exists"
Uncommitted changes during checkout"your local changes would be overwritten"
Authentication failure"authentication required but no callback set"
Network unreachable"failed to connect"

Gitty passes through the raw libgit2 error code in error.code when available. A full list of libgit2 error codes is available in the libgit2 API reference.