Skip to content

Commit

Permalink
Merge pull request #265 from jvanbuel/feature/anyhow-error-handling
Browse files Browse the repository at this point in the history
feat: use anyhow instead of custom errors
  • Loading branch information
jvanbuel authored Dec 4, 2024
2 parents d402b82 + bd974cc commit 3e5fcbd
Show file tree
Hide file tree
Showing 26 changed files with 41 additions and 169 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ formula = "flowrs"

[dependencies]
ansi-to-tui = { version = "7.0.0" }
anyhow = "1.0.94"
backtrace = "0.3.73"
chrono = "0.4.38"
clap = { version = "^4.5", features = ["derive", "env"] }
Expand Down
5 changes: 2 additions & 3 deletions src/airflow/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ pub mod dagstats;
pub mod logs;
pub mod taskinstances;

use crate::app::error::Result;
use anyhow::Result;
use std::time::Duration;

use log::info;
use reqwest::{Method, Url};

use crate::airflow::config::{AirflowAuth, AirflowConfig};
use crate::app::error::{ConfigError, FlowrsError};

#[derive(Debug, Clone)]
pub struct AirFlowClient {
Expand Down Expand Up @@ -56,7 +55,7 @@ impl AirFlowClient {
if let Some(token) = &token.token {
return Ok(self.client.request(method, url).bearer_auth(token.trim()));
}
Err(FlowrsError::ConfigError(ConfigError::NoTokenOrCmd))
Err(anyhow::anyhow!("Token not found"))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/airflow/client/dagruns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use log::debug;
use reqwest::{Method, Response};

use crate::airflow::model::dagrun::DagRunList;
use crate::app::error::Result;
use anyhow::Result;

use super::AirFlowClient;

Expand Down
2 changes: 1 addition & 1 deletion src/airflow/client/dags.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::app::error::Result;
use anyhow::Result;
use log::error;
use reqwest::{Method, Response};

Expand Down
3 changes: 2 additions & 1 deletion src/airflow/client/dagstats.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{airflow::model::dagstats::DagStatsResponse, app::error::Result};
use crate::airflow::model::dagstats::DagStatsResponse;
use reqwest::Method;
use anyhow::Result;

use super::AirFlowClient;

Expand Down
2 changes: 1 addition & 1 deletion src/airflow/client/logs.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use reqwest::Method;

use crate::airflow::model::log::Log;
use crate::app::error::Result;
use anyhow::Result;

use super::AirFlowClient;

Expand Down
3 changes: 1 addition & 2 deletions src/airflow/client/taskinstances.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::app::error::Result;

use anyhow::Result;
use log::{debug, info};
use reqwest::{Method, Response};

Expand Down
2 changes: 1 addition & 1 deletion src/airflow/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use serde::{Deserialize, Serialize};
use strum::EnumIter;

use super::managed_services::conveyor::get_conveyor_environment_servers;
use crate::app::error::Result;
use crate::CONFIG_FILE;
use anyhow::Result;

#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, ValueEnum, EnumIter)]
pub enum ManagedService {
Expand Down
2 changes: 1 addition & 1 deletion src/airflow/managed_services/conveyor.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::airflow::config::{AirflowAuth, AirflowConfig, ManagedService, TokenCmd};
use crate::app::error::Result;
use log::info;
use serde::{Deserialize, Serialize};
use anyhow::Result;

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ConveyorEnvironment {
Expand Down
1 change: 0 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use worker::{Worker, WorkerMessage};

use crate::{airflow::client::AirFlowClient, ui::draw_ui};

pub mod error;
pub mod events;
pub mod model;
pub mod state;
Expand Down
136 changes: 0 additions & 136 deletions src/app/error.rs

This file was deleted.

4 changes: 2 additions & 2 deletions src/app/model/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ use crate::app::worker::WorkerMessage;
use crate::ui::constants::{ALTERNATING_ROW_COLOR, DEFAULT_STYLE};

use super::{filter::Filter, Model, StatefulTable};
use crate::app::error::FlowrsError;
use crate::ui::common::create_headers;
use anyhow::Error;

pub struct ConfigModel {
pub all: Vec<AirflowConfig>,
pub filtered: StatefulTable<AirflowConfig>,
pub filter: Filter,
#[allow(dead_code)]
pub errors: Vec<FlowrsError>,
pub errors: Vec<Error>,
}

impl ConfigModel {
Expand Down
4 changes: 2 additions & 2 deletions src/app/model/dagruns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use super::popup::dagruns::DagRunPopUp;
use super::popup::popup_area;
use super::popup::{dagruns::clear::ClearDagRunPopup, dagruns::mark::MarkDagRunPopup};
use super::{filter::Filter, Model, StatefulTable};
use crate::app::error::FlowrsError;
use crate::app::worker::WorkerMessage;
use anyhow::Error;

pub struct DagRunModel {
pub dag_id: Option<String>,
Expand All @@ -38,7 +38,7 @@ pub struct DagRunModel {
pub filter: Filter,
pub marked: Vec<usize>,
#[allow(dead_code)]
pub errors: Vec<FlowrsError>,
pub errors: Vec<Error>,
pub popup: Option<DagRunPopUp>,
pub commands: Option<CommandPopUp<'static, 6>>,
ticks: u32,
Expand Down
8 changes: 4 additions & 4 deletions src/app/model/dags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ use crate::ui::constants::{AirflowStateColor, ALTERNATING_ROW_COLOR, DEFAULT_STY

use super::popup::commands_help::CommandPopUp;
use super::{filter::Filter, Model, StatefulTable};
use crate::app::error::FlowrsError;
use crate::app::worker::WorkerMessage;
use anyhow::Error;

pub struct DagModel {
pub all: Vec<Dag>,
pub dag_stats: HashMap<String, Vec<DagStatistic>>,
pub filtered: StatefulTable<Dag>,
pub filter: Filter,
#[allow(dead_code)]
pub errors: Vec<FlowrsError>,
pub errors: Vec<Error>,
commands: Option<CommandPopUp<'static, 2>>,
ticks: u32,
event_buffer: Vec<FlowrsEvent>,
Expand Down Expand Up @@ -130,7 +130,7 @@ impl Model for DagModel {
}
None => self
.errors
.push(FlowrsError::from(String::from("No dag selected"))),
.push(Error::msg("No DAG selected to pause/resume")),
},
KeyCode::Char('/') => {
self.filter.toggle();
Expand All @@ -152,7 +152,7 @@ impl Model for DagModel {
);
} else {
self.errors
.push(FlowrsError::from(String::from("No dag selected")));
.push(Error::msg("No DAG selected to view DAG Runs"));
}
}
KeyCode::Char('g') => {
Expand Down
5 changes: 3 additions & 2 deletions src/app/model/logs.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use anyhow::Error;
use crossterm::event::KeyCode;
use ratatui::{
buffer::Buffer,
Expand All @@ -13,7 +14,7 @@ use regex::Regex;

use crate::{
airflow::model::log::Log,
app::{error::FlowrsError, events::custom::FlowrsEvent, worker::WorkerMessage},
app::{events::custom::FlowrsEvent, worker::WorkerMessage},
ui::constants::DM_RGB,
};

Expand All @@ -27,7 +28,7 @@ pub struct LogModel {
pub all: Vec<Log>,
pub current: usize,
#[allow(dead_code)]
pub errors: Vec<FlowrsError>,
pub errors: Vec<Error>,
ticks: u32,
vertical_scroll: usize,
vertical_scroll_state: ScrollbarState,
Expand Down
4 changes: 2 additions & 2 deletions src/app/model/taskinstances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use super::popup::taskinstances::clear::ClearTaskInstancePopup;
use super::popup::taskinstances::mark::MarkTaskInstancePopup;
use super::popup::taskinstances::TaskInstancePopUp;
use super::{filter::Filter, Model, StatefulTable};
use crate::app::error::FlowrsError;
use crate::app::worker::WorkerMessage;
use anyhow::Error;

pub struct TaskInstanceModel {
pub dag_id: Option<String>,
Expand All @@ -31,7 +31,7 @@ pub struct TaskInstanceModel {
pub filtered: StatefulTable<TaskInstance>,
pub filter: Filter,
#[allow(dead_code)]
pub errors: Vec<FlowrsError>,
pub errors: Vec<Error>,
pub popup: Option<TaskInstancePopUp>,
pub marked: Vec<usize>,
commands: Option<CommandPopUp<'static, 3>>,
Expand Down
2 changes: 1 addition & 1 deletion src/app/state.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::airflow::config::FlowrsConfig;
use crate::app::error::Result;
use crate::app::model::dagruns::DagRunModel;
use crate::app::model::dags::DagModel;
use anyhow::Result;

use super::model::{config::ConfigModel, logs::LogModel, taskinstances::TaskInstanceModel};

Expand Down
2 changes: 1 addition & 1 deletion src/commands/config/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use log::info;
use strum::IntoEnumIterator;

use super::model::AddCommand;
use crate::app::error::Result;
use crate::{
airflow::config::{AirflowAuth, AirflowConfig, BasicAuth, FlowrsConfig, TokenCmd},
commands::config::model::{validate_endpoint, ConfigOption},
};
use anyhow::Result;

impl AddCommand {
pub fn run(&self) -> Result<()> {
Expand Down
Loading

0 comments on commit 3e5fcbd

Please sign in to comment.