radicle_git_ext/error.rs
1// Copyright © 2019-2020 The Radicle Foundation <hello@radicle.foundation>
2//
3// This file is part of radicle-link, distributed under the GPLv3 with Radicle
4// Linking Exception. For full terms see the included LICENSE file.
5
6use std::{fmt::Display, io};
7
8pub fn is_not_found_err(e: &git2::Error) -> bool {
9 e.code() == git2::ErrorCode::NotFound
10}
11
12pub fn is_exists_err(e: &git2::Error) -> bool {
13 e.code() == git2::ErrorCode::Exists
14}
15
16pub fn into_git_err<E: Display>(e: E) -> git2::Error {
17 git2::Error::from_str(&e.to_string())
18}
19
20pub fn into_io_err(e: git2::Error) -> io::Error {
21 io::Error::new(io::ErrorKind::Other, e)
22}