Skip to content

Commit

Permalink
cli: simplify error annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
blitz committed Dec 17, 2024
1 parent e04478c commit 443ed11
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
9 changes: 4 additions & 5 deletions src/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ SOFTWARE.
//! [`fetch_results`] is the entry point.
use crate::gitlab_api::types::Response;
use anyhow::Context;
use chrono::{DateTime, Local, NaiveDate, NaiveTime};
use reqwest::blocking::Client;
use reqwest::header::AUTHORIZATION;
Expand Down Expand Up @@ -90,16 +91,14 @@ fn fetch_result(
.header(AUTHORIZATION, authorization)
.json(&payload)
.send()
.map_err(anyhow::Error::from)
.map_err(|e| e.context("Failed to send request"))?
.context("Failed to send request")?
.error_for_status()
.map_err(anyhow::Error::from)
.map_err(|e| e.context("Failed to receive proper response"))?;
.context("Failed to receive response")?;

plain_response
.json::<Response>()
.context("Failed to parse response body as JSON")
.map_err(anyhow::Error::from)
.map_err(|e| e.context("Failed to parse response body as JSON"))
}

/// Fetches all results from the API with pagination in mind.
Expand Down
15 changes: 1 addition & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,7 @@ fn main() -> Result<(), Box<dyn Error>> {
cfg.token(),
cfg.after(),
cfg.before(),
);

let response = match response {
Ok(data) => data,
Err(err) => {
eprintln!();
eprintln!("{}", Color::Red.bold().paint("Error:"));

for e in err.chain() {
eprintln!(" {e}");
}
std::process::exit(1);
}
};
)?;

// All nodes but as vector to references.
// Simplifies the handling with other parts of the code, especially the
Expand Down

0 comments on commit 443ed11

Please sign in to comment.