aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/git.rs13
-rw-r--r--src/github.rs13
-rw-r--r--src/main.rs3
3 files changed, 25 insertions, 4 deletions
diff --git a/src/git.rs b/src/git.rs
index d83d2b6..7ad919f 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -1,6 +1,15 @@
+use thiserror;
+
use std::path::Path;
+#[derive(Debug, thiserror::Error)]
+pub enum Error {
+ #[error("git error")]
+ Git(#[from] git2::Error),
+}
+
+
/// Mirror a repository.
///
/// Works like:
@@ -12,7 +21,7 @@ pub fn mirror<P: AsRef<Path>>(
url: &str,
path: P,
description: Option<&str>,
-) -> Result<(), Box<dyn std::error::Error>> {
+) -> Result<(), Error> {
let mut repo_init_options = git2::RepositoryInitOptions::new();
repo_init_options.bare(true);
@@ -51,7 +60,7 @@ pub fn mirror<P: AsRef<Path>>(
/// ```
pub fn update<P: AsRef<Path>>(
path: P,
-) -> Result<(), Box<dyn std::error::Error>> {
+) -> Result<(), Error> {
let repo = git2::Repository::open_bare(path)?;
for remote_opt in &repo.remotes()? {
diff --git a/src/github.rs b/src/github.rs
index 8c853da..0b20abd 100644
--- a/src/github.rs
+++ b/src/github.rs
@@ -1,5 +1,6 @@
use reqwest::blocking::ClientBuilder;
use serde::Deserialize;
+use thiserror;
const USER_AGENT: &'static str = concat!(
@@ -9,6 +10,16 @@ const USER_AGENT: &'static str = concat!(
);
+#[derive(Debug, thiserror::Error)]
+pub enum Error {
+ #[error("request error")]
+ Http(#[from] reqwest::Error),
+
+ #[error("request header error")]
+ Header(#[from] reqwest::header::InvalidHeaderValue),
+}
+
+
#[derive(Debug, Deserialize)]
pub struct Repo {
pub id: i64,
@@ -21,7 +32,7 @@ pub struct Repo {
}
-pub fn fetch_repos() -> Result<Vec<Repo>, Box<dyn std::error::Error>> {
+pub fn fetch_repos() -> Result<Vec<Repo>, Error> {
let mut headers = reqwest::header::HeaderMap::new();
headers.insert("Accept", "application/vnd.github.v3+json".parse()?);
diff --git a/src/main.rs b/src/main.rs
index 162c743..ffda552 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,4 @@
+use anyhow;
use sqlx;
use tokio;
@@ -80,7 +81,7 @@ async fn main() {
}
-fn mirror(repo: &github::Repo) -> Result<(), Box<dyn std::error::Error>> {
+fn mirror(repo: &github::Repo) -> anyhow::Result<()> {
// mirror database
// update description
// copy cgitrc