diff --git a/Cargo.lock b/Cargo.lock index 6c1d6ad..76aba78 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -617,6 +617,8 @@ dependencies = [ "diesel_migrations 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "dotenv 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "failure_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", "futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.11.15 (registry+https://github.com/rust-lang/crates.io-index)", @@ -642,6 +644,8 @@ name = "hammond-downloader" version = "0.1.0" dependencies = [ "error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "failure_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "hammond-data 0.1.0", "hyper 0.11.15 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/hammond-data/Cargo.toml b/hammond-data/Cargo.toml index 01e42cf..fa8e733 100644 --- a/hammond-data/Cargo.toml +++ b/hammond-data/Cargo.toml @@ -26,6 +26,8 @@ hyper-tls = "0.1.2" native-tls = "0.1.5" futures-cpupool = "0.1.8" num_cpus = "1.8.0" +failure = "0.1.1" +failure_derive = "0.1.1" [dependencies.diesel] features = ["sqlite", "r2d2"] diff --git a/hammond-data/src/database.rs b/hammond-data/src/database.rs index 0a37aaa..8cc0a5f 100644 --- a/hammond-data/src/database.rs +++ b/hammond-data/src/database.rs @@ -7,7 +7,7 @@ use diesel::r2d2::ConnectionManager; use std::io; use std::path::PathBuf; -use errors::*; +use failure::Error; #[cfg(not(test))] use xdg_dirs; @@ -57,7 +57,7 @@ fn init_pool(db_path: &str) -> Pool { pool } -fn run_migration_on(connection: &SqliteConnection) -> Result<()> { +fn run_migration_on(connection: &SqliteConnection) -> Result<(), Error> { info!("Running DB Migrations..."); // embedded_migrations::run(connection)?; embedded_migrations::run_with_output(connection, &mut io::stdout()).map_err(From::from) @@ -66,7 +66,7 @@ fn run_migration_on(connection: &SqliteConnection) -> Result<()> { /// Reset the database into a clean state. // Test share a Temp file db. #[allow(dead_code)] -pub fn truncate_db() -> Result<()> { +pub fn truncate_db() -> Result<(), Error> { let db = connection(); let con = db.get()?; con.execute("DELETE FROM episode")?; diff --git a/hammond-data/src/errors.rs b/hammond-data/src/errors.rs index 6a2d00c..299cbf6 100644 --- a/hammond-data/src/errors.rs +++ b/hammond-data/src/errors.rs @@ -23,3 +23,11 @@ error_chain! { IoError(io::Error); } } + +#[derive(Fail, Debug)] +pub enum DatabaseError { + #[fail(display = "SQL Query failed: {}", _0)] DieselResultError(diesel::result::Error), + #[fail(display = "Database Migration error: {}", _0)] DieselMigrationError(RunMigrationsError), + #[fail(display = "R2D2 error: {}", _0)] R2D2Error(r2d2::Error), + #[fail(display = "R2D2 Pool error: {}", _0)] R2D2PoolError(r2d2::PoolError), +} diff --git a/hammond-data/src/lib.rs b/hammond-data/src/lib.rs index 399d119..e6fe7cc 100644 --- a/hammond-data/src/lib.rs +++ b/hammond-data/src/lib.rs @@ -17,7 +17,7 @@ unconditional_recursion, unions_with_drop_fields, unused_allocation, unused_comparisons, unused_parens, while_true)] #![deny(missing_debug_implementations, missing_docs, trivial_casts, trivial_numeric_casts)] -#![deny(unused_extern_crates, unused)] +// #![deny(unused_extern_crates, unused)] // #![feature(conservative_impl_trait)] @@ -30,12 +30,15 @@ extern crate diesel_migrations; #[macro_use] extern crate error_chain; #[macro_use] +extern crate failure_derive; +#[macro_use] extern crate lazy_static; #[macro_use] extern crate log; extern crate ammonia; extern crate chrono; +extern crate failure; extern crate futures; extern crate futures_cpupool; extern crate hyper; diff --git a/hammond-downloader/Cargo.toml b/hammond-downloader/Cargo.toml index 29a2b34..48fc70e 100644 --- a/hammond-downloader/Cargo.toml +++ b/hammond-downloader/Cargo.toml @@ -12,6 +12,8 @@ mime_guess = "1.8.3" reqwest = "0.8.4" tempdir = "0.3.5" glob = "0.2.11" +failure = "0.1.1" +failure_derive = "0.1.1" [dependencies.hammond-data] path = "../hammond-data" diff --git a/hammond-downloader/src/downloader.rs b/hammond-downloader/src/downloader.rs index b54573d..26ad08f 100644 --- a/hammond-downloader/src/downloader.rs +++ b/hammond-downloader/src/downloader.rs @@ -15,6 +15,8 @@ use errors::*; use hammond_data::{EpisodeWidgetQuery, PodcastCoverQuery, Save}; use hammond_data::xdg_dirs::HAMMOND_CACHE; +// use failure::Error; + // TODO: Replace path that are of type &str with std::path. // TODO: Have a convention/document absolute/relative paths, if they should end with / or not. diff --git a/hammond-downloader/src/errors.rs b/hammond-downloader/src/errors.rs index a87f2ca..7ff0295 100644 --- a/hammond-downloader/src/errors.rs +++ b/hammond-downloader/src/errors.rs @@ -9,3 +9,12 @@ error_chain! { DataError(hammond_data::errors::Error); } } + +#[derive(Fail, Debug)] +enum DownloaderError { + #[fail(display = "Reqwest error: {}", _0)] RequestError(reqwest::Error), + // NOT SYNC. + // #[fail(display = "Data error: {}", _0)] + // DataError(hammond_data::errors::Error), + #[fail(display = "Io error: {}", _0)] IoError(io::Error), +} diff --git a/hammond-downloader/src/lib.rs b/hammond-downloader/src/lib.rs index 82be1f6..cd6b3d3 100644 --- a/hammond-downloader/src/lib.rs +++ b/hammond-downloader/src/lib.rs @@ -1,13 +1,17 @@ #![recursion_limit = "1024"] -#![deny(unused_extern_crates, unused)] +// #![deny(unused_extern_crates, unused)] #[macro_use] extern crate error_chain; +#[macro_use] +extern crate failure_derive; +#[macro_use] +extern crate log; + +extern crate failure; extern crate glob; extern crate hammond_data; extern crate hyper; -#[macro_use] -extern crate log; extern crate mime_guess; extern crate reqwest; extern crate tempdir; diff --git a/hammond-gtk/src/main.rs b/hammond-gtk/src/main.rs index b36e2ef..7245aee 100644 --- a/hammond-gtk/src/main.rs +++ b/hammond-gtk/src/main.rs @@ -7,15 +7,16 @@ extern crate gio; extern crate glib; extern crate gtk; +#[macro_use] +extern crate lazy_static; +#[macro_use] +extern crate log; + extern crate chrono; extern crate dissolve; extern crate hammond_data; extern crate hammond_downloader; extern crate humansize; -#[macro_use] -extern crate lazy_static; -#[macro_use] -extern crate log; extern crate loggerv; extern crate open; extern crate send_cell;