Skip to content

Commit

Permalink
Remove thiserror and use color-eyre in its stead
Browse files Browse the repository at this point in the history
  • Loading branch information
AbooMinister25 committed Jul 11, 2024
1 parent d33a99c commit 0822ad3
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 89 deletions.
93 changes: 76 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
color-eyre = "0.6.3"
figment = { version = "0.10.19", features = ["env", "toml"] }
flate2 = "1.0.30"
log = "0.4.21"
Expand All @@ -12,7 +13,6 @@ parking_lot = "0.12.3"
reqwest = { version = "0.12.4", features = ["blocking", "json", "gzip"] }
serde = { version = "1.0.203", features = ["derive"] }
tar = "0.4.40"
thiserror = "1.0.61"
threadpool = "1.8.1"
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
Expand Down
14 changes: 6 additions & 8 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ mod models;
pub use methods::*;
pub use models::*;

use crate::{error::DragonflyError, APP_CONFIG};
use crate::APP_CONFIG;
use color_eyre::Result;
use flate2::read::GzDecoder;
use parking_lot::RwLock;
use reqwest::{blocking::Client, Url};
Expand Down Expand Up @@ -38,7 +39,7 @@ pub struct DragonflyClient {
}

impl DragonflyClient {
pub fn new() -> Result<Self, DragonflyError> {
pub fn new() -> Result<Self> {
let client = Client::builder().gzip(true).build()?;

let auth_response = fetch_access_token(&client)?;
Expand Down Expand Up @@ -105,7 +106,7 @@ impl DragonflyClient {
}

/// Update the global ruleset. Waits for a write lock.
pub fn update_rules(&self) -> Result<(), DragonflyError> {
pub fn update_rules(&self) -> Result<()> {
let response = fetch_rules(
self.get_http_client(),
&self.authentication_state.read().access_token,
Expand Down Expand Up @@ -150,10 +151,7 @@ impl DragonflyClient {
}
}

pub fn fetch_tarball(
http_client: &Client,
download_url: &Url,
) -> Result<TarballType, DragonflyError> {
pub fn fetch_tarball(http_client: &Client, download_url: &Url) -> Result<TarballType> {
let response = http_client.get(download_url.clone()).send()?;

let decompressed = GzDecoder::new(response);
Expand All @@ -165,7 +163,7 @@ pub fn fetch_tarball(
Ok(tar::Archive::new(cursor))
}

pub fn fetch_zipfile(http_client: &Client, download_url: &Url) -> Result<ZipType, DragonflyError> {
pub fn fetch_zipfile(http_client: &Client, download_url: &Url) -> Result<ZipType> {
let response = http_client.get(download_url.to_string()).send()?;

let mut cursor = Cursor::new(Vec::new());
Expand Down
5 changes: 2 additions & 3 deletions src/client/models.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use color_eyre::Result;
use serde::Serialize;
use serde::{self, Deserialize};
use std::collections::HashMap;
use std::fmt::Display;
use yara::{Compiler, Rules};

use crate::error::DragonflyError;

#[derive(Debug, Serialize, PartialEq)]
pub struct SubmitJobResultsSuccess {
pub name: String,
Expand Down Expand Up @@ -53,7 +52,7 @@ pub struct RulesResponse {

impl RulesResponse {
/// Compile the rules from the response
pub fn compile(&self) -> Result<Rules, DragonflyError> {
pub fn compile(&self) -> Result<Rules> {
let rules_str = self
.rules
.values()
Expand Down
49 changes: 0 additions & 49 deletions src/error.rs

This file was deleted.

9 changes: 5 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
mod app_config;
mod client;
mod error;
mod exts;
mod scanner;
mod utils;

use std::{sync::Arc, time::Duration};

use client::DragonflyClient;
use error::DragonflyError;
use color_eyre::eyre::Result;
use reqwest::blocking::Client;
use threadpool::ThreadPool;
use tracing::{debug, error, info, span, trace, Level};
Expand All @@ -30,7 +29,7 @@ fn scanner(
job: &Job,
rules: &Rules,
commit_hash: &str,
) -> Result<PackageScanResults, DragonflyError> {
) -> Result<PackageScanResults> {
let distribution_scan_results = scan_all_distributions(http_client, rules, job)?;

let package_scan_result = PackageScanResults::new(
Expand Down Expand Up @@ -76,7 +75,9 @@ fn runner(client: &DragonflyClient, job: Job) {
}
}

fn main() -> Result<(), DragonflyError> {
fn main() -> Result<()> {
color_eyre::install()?;

let default_env_filter = EnvFilter::builder()
.parse("warn,dragonfly_client_rs=info")
.unwrap();
Expand Down
Loading

0 comments on commit 0822ad3

Please sign in to comment.