Skip to content

Commit

Permalink
Convert Error path to Sync + Send
Browse files Browse the repository at this point in the history
Signed-off-by: 35V LG84 <[email protected]>
  • Loading branch information
35VLG84 committed Feb 12, 2025
1 parent e37e4b4 commit d68c01b
Show file tree
Hide file tree
Showing 38 changed files with 201 additions and 194 deletions.
18 changes: 8 additions & 10 deletions tackler-api/src/filters/filter_definition.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* Tackler-NG 2023-2024
* Tackler-NG 2023-2025
* SPDX-License-Identifier: Apache-2.0
*/

use crate::filters::IndentDisplay;
use crate::filters::TxnFilter;
use crate::tackler;
use base64::{Engine as _, engine::general_purpose};
use jiff::tz::TimeZone;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -63,7 +63,7 @@ impl FilterDefinition {
///
/// # Examples
/// ```
/// # use std::error::Error;
/// # use tackler_api::tackler;
/// # use tackler_api::filters::FilterDefinition;
/// # use tackler_api::filters::TxnFilter;
///
Expand All @@ -76,9 +76,9 @@ impl FilterDefinition {
/// _ => panic!(),
/// }
///
/// # Ok::<(), Box<dyn Error>>(())
/// # Ok::<(), tackler::Error>(())
/// ```
pub fn from_json_str(filt_str: &str) -> Result<FilterDefinition, Box<dyn std::error::Error>> {
pub fn from_json_str(filt_str: &str) -> Result<FilterDefinition, tackler::Error> {
match serde_json::from_str::<FilterDefinition>(filt_str) {
Ok(flt) => Ok(flt),
Err(err) => {
Expand All @@ -99,7 +99,7 @@ impl FilterDefinition {
///
/// # Examples
/// ```
/// # use std::error::Error;
/// # use tackler_api::tackler;
/// # use tackler_api::filters::FilterDefinition;
/// # use tackler_api::filters::TxnFilter;
///
Expand All @@ -112,11 +112,9 @@ impl FilterDefinition {
/// _ => panic!(),
/// }
///
/// # Ok::<(), Box<dyn Error>>(())
/// # Ok::<(), tackler::Error>(())
/// ```
pub fn from_armor(
filt_armor_str: &str,
) -> Result<FilterDefinition, Box<dyn std::error::Error>> {
pub fn from_armor(filt_armor_str: &str) -> Result<FilterDefinition, tackler::Error> {
let filt_armor = if FilterDefinition::is_armored(filt_armor_str) {
filt_armor_str.trim_start_matches(FilterDefinition::FILTER_ARMOR)
} else {
Expand Down
8 changes: 7 additions & 1 deletion tackler-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Tackler-NG 2022-2023
* Tackler-NG 2022-2025
* SPDX-License-Identifier: Apache-2.0
*/
#![forbid(unsafe_code)]
Expand All @@ -12,3 +12,9 @@ pub mod filters;
pub mod location;
pub mod txn_header;
pub mod txn_ts;

/// Generic Tackler namespace
pub mod tackler {
/// Generic error type
pub type Error = Box<dyn std::error::Error + Send + Sync>;
}
6 changes: 3 additions & 3 deletions tackler-api/src/location.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* Tackler-NG 2022
* Tackler-NG 2022-2025
* SPDX-License-Identifier: Apache-2.0
*/

//! Transaction Geo location
//!
use crate::tackler;
use rust_decimal::Decimal;
use std::error::Error;
use std::fmt::{Display, Formatter};

/// Geo Point
Expand Down Expand Up @@ -46,7 +46,7 @@ impl GeoPoint {
lat: Decimal,
lon: Decimal,
alt: Option<Decimal>,
) -> Result<GeoPoint, Box<dyn Error>> {
) -> Result<GeoPoint, tackler::Error> {
if lat < Self::MIN_LAT || Self::MAX_LAT < lat {
let msg = format!("Value out of specification for Latitude: {lat}");
return Err(msg.into());
Expand Down
10 changes: 5 additions & 5 deletions tackler-api/src/txn_ts.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Tackler-NG 2023-2024
* Tackler-NG 2023-2025
* SPDX-License-Identifier: Apache-2.0
*/

Expand All @@ -8,10 +8,10 @@
//! `txn_ts` is collection of utilities to generate
//! different representations of Txn timestamps.
//!
use crate::tackler;
use jiff::Zoned;
use jiff::fmt::strtime;
use jiff::tz::{Offset, TimeZone};
use std::error::Error;

/// UTC Timezone
pub static TZ_UTC: Offset = jiff::tz::Offset::UTC;
Expand Down Expand Up @@ -41,7 +41,7 @@ impl TimestampStyle {
pub const FULL: &'static str = "full";

/// Get Timestamp style by name
pub fn from(name: &str) -> Result<Self, Box<dyn Error>> {
pub fn from(name: &str) -> Result<Self, tackler::Error> {
match name {
TimestampStyle::DATE => Ok(TimestampStyle::Date),
TimestampStyle::SECONDS => Ok(TimestampStyle::Secodns),
Expand Down Expand Up @@ -85,7 +85,7 @@ impl GroupBy {
pub const ISO_WEEK_DATE: &'static str = "iso-week-date";

/// Get 'group by' -selector based on UI/CFG name
pub fn from(group_by: &str) -> Result<GroupBy, Box<dyn Error>> {
pub fn from(group_by: &str) -> Result<GroupBy, tackler::Error> {
match group_by {
GroupBy::ISO_WEEK_DATE => Ok(GroupBy::IsoWeekDate),
GroupBy::ISO_WEEK => Ok(GroupBy::IsoWeek),
Expand All @@ -107,7 +107,7 @@ impl GroupBy {
}
}
/// Get zoned ts from RFC 3339 string
pub fn rfc3339_to_zoned(rfc3339_str: &str) -> Result<Zoned, Box<dyn Error>> {
pub fn rfc3339_to_zoned(rfc3339_str: &str) -> Result<Zoned, tackler::Error> {
strtime::parse("%Y-%m-%dT%H:%M:%S%.f%:z", rfc3339_str)?
.to_zoned()
.map_err(|e| {
Expand Down
5 changes: 2 additions & 3 deletions tackler-cli/src/cli_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
use clap::builder::{PossibleValue, TypedValueParser};
use clap::error::{ContextKind, ContextValue, ErrorKind};
use clap::{CommandFactory, Parser, Subcommand};
use std::error::Error;
use std::path::PathBuf;
use tackler_api::txn_ts;
use tackler_core::config;
use tackler_core::config::PriceLookupType;
use tackler_core::config::overlaps::{
AuditOverlap, OverlapConfig, PriceOverlap, ReportOverlap, StrictOverlap,
};
use tackler_core::kernel::Settings;
use tackler_core::kernel::settings::{FileInput, FsInput, GitInput, InputSettings};
use tackler_core::parser::GitInputSelector;
use tackler_core::{config, tackler};

pub(crate) const PRICE_BEFORE: &str = "price.before";
//
Expand Down Expand Up @@ -360,7 +359,7 @@ impl DefaultModeArgs {
pub(crate) fn get_input_type(
&self,
settings: &Settings,
) -> Result<InputSettings, Box<dyn Error>> {
) -> Result<InputSettings, tackler::Error> {
let git_selector = self.get_git_selector();

if let Some(filename) = &self.input_filename {
Expand Down
4 changes: 2 additions & 2 deletions tackler-cli/src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* Tackler-NG 2025
* SPDX-License-Identifier: Apache-2.0
*/
use std::error::Error;
use std::fs;
use std::path::Path;
use tackler_core::tackler;

mod accounts_toml;
mod commodities_toml;
Expand All @@ -13,7 +13,7 @@ mod tackler_toml;
mod tags_toml;
mod welcome_txn;

pub(crate) fn exec(name: &str) -> Result<(), Box<dyn Error>> {
pub(crate) fn exec(name: &str) -> Result<(), tackler::Error> {
let conf_dir = Path::new(name).join("conf");
let txns_dir = Path::new(name).join("txns");

Expand Down
4 changes: 2 additions & 2 deletions tackler-cli/src/commands/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* SPDX-License-Identifier: Apache-2.0
*/
use crate::commands::init;
use std::error::Error;
use std::fs;
use std::path::Path;
use tackler_core::tackler;

pub(crate) fn exec(name: &str) -> Result<(), Box<dyn Error>> {
pub(crate) fn exec(name: &str) -> Result<(), tackler::Error> {
if fs::exists(name)? {
let p = Path::new(name).canonicalize()?;
return Err(format!("destination `{}` already exists", &p.display()).into());
Expand Down
5 changes: 2 additions & 3 deletions tackler-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ mod cli_args;
mod commands;

use log::error;
use std::error::Error;
use std::io;
use tackler_core::export::write_exports;
use tackler_core::kernel::settings::Settings;
use tackler_core::parser;
use tackler_core::report::write_txt_reports;
use tackler_core::{parser, tackler};

use clap::Parser;
use tackler_api::filters::FilterDefinition;
Expand All @@ -28,7 +27,7 @@ use tikv_jemallocator::Jemalloc;
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;

fn run(cli: DefaultModeArgs) -> Result<(), Box<dyn Error>> {
fn run(cli: DefaultModeArgs) -> Result<(), tackler::Error> {
let cfg = match Config::from(cli.conf_path.as_ref().unwrap()) {
Ok(cfg) => cfg,
Err(err) => {
Expand Down
7 changes: 3 additions & 4 deletions tackler-core/src/bin/git_bench.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
/*
* Tackler-NG 2019-2024
* Tackler-NG 2019-2025
* SPDX-License-Identifier: Apache-2.0
*/
use std::error::Error;
use std::path::Path;
use std::time::{SystemTime, UNIX_EPOCH};
use tackler_api::metadata::items::MetadataItem;
use tackler_core::kernel::Settings;
use tackler_core::model::TxnData;
use tackler_core::parser;
use tackler_core::parser::GitInputSelector;
use tackler_core::{parser, tackler};

#[cfg(not(target_env = "msvc"))]
use tikv_jemallocator::Jemalloc;
Expand All @@ -28,7 +27,7 @@ const TXN_SET_1E5_CHECKSUM: &str =
const TXN_SET_1E5_COMMIT_ID: &str = "cb56fdcdd2b56d41fc08cc5af4a3b410896f03b5";

#[rustfmt::skip]
fn verify_git_run(result: Result<TxnData, Box<dyn Error>>, commit: &str, checksum: &str) {
fn verify_git_run(result: Result<TxnData, tackler::Error>, commit: &str, checksum: &str) {
match result {
Ok(txn_data) => {
let txn_set = txn_data.get_all().unwrap(/*:test:*/);
Expand Down
12 changes: 6 additions & 6 deletions tackler-core/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Tackler-NG 2024
* Tackler-NG 2024-2025
* SPDX-License-Identifier: Apache-2.0
*/
pub(crate) use items::AccountSelectors;
Expand All @@ -13,22 +13,22 @@ pub(crate) use items::Report;
pub use items::ReportType;
pub(crate) use items::Scale;
pub use items::StorageType;
use std::error::Error;

use crate::tackler;
pub use items::NONE_VALUE;

mod items;
pub mod overlaps;
mod raw_items;

pub fn to_report_targets(targets: &[String]) -> Result<Vec<ReportType>, Box<dyn Error>> {
pub fn to_report_targets(targets: &[String]) -> Result<Vec<ReportType>, tackler::Error> {
let trgs =
targets.iter().try_fold(
Vec::new(),
|mut trgs: Vec<ReportType>, trg| match ReportType::from(trg.as_str()) {
Ok(t) => {
trgs.push(t);
Ok::<Vec<ReportType>, Box<dyn Error>>(trgs)
Ok::<Vec<ReportType>, tackler::Error>(trgs)
}
Err(e) => {
let msg = format!("Invalid report target: {e}");
Expand All @@ -39,14 +39,14 @@ pub fn to_report_targets(targets: &[String]) -> Result<Vec<ReportType>, Box<dyn
Ok(trgs)
}

pub fn to_export_targets(targets: &[String]) -> Result<Vec<ExportType>, Box<dyn Error>> {
pub fn to_export_targets(targets: &[String]) -> Result<Vec<ExportType>, tackler::Error> {
let trgs =
targets.iter().try_fold(
Vec::new(),
|mut trgs: Vec<ExportType>, trg| match ExportType::from(trg.as_str()) {
Ok(t) => {
trgs.push(t);
Ok::<Vec<ExportType>, Box<dyn Error>>(trgs)
Ok::<Vec<ExportType>, tackler::Error>(trgs)
}
Err(e) => {
let msg = format!("Invalid export target: {e}");
Expand Down
Loading

0 comments on commit d68c01b

Please sign in to comment.