Verified Commit f9f015a2 authored by Jordan Petridis's avatar Jordan Petridis 🌱

Hammond-data: switch database module to use Failure.

parent 38742350
......@@ -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)",
......
......@@ -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"]
......
......@@ -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")?;
......
......@@ -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),
}
......@@ -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;
......
......@@ -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"
......
......@@ -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.
......
......@@ -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),
}
#![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;
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment