Error handling cleanup.

This commit is contained in:
Jordan Petridis 2017-10-04 23:51:53 +03:00
parent f25ce64e34
commit bf9e544a2b
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
9 changed files with 29 additions and 43 deletions

View File

@ -4,24 +4,13 @@ version = "0.1.0"
authors = ["Jordan Petridis <jordanpetridis@protonmail.com>"]
[dependencies]
rfc822_sanitizer = "0.3.0"
rayon = "0.8.2"
regex = "0.2"
error-chain = "0.11.0"
structopt = "0.1.0"
structopt-derive = "0.1.0"
log = "0.3.8"
loggerv = "0.3.0"
reqwest = "0.7.3"
hyper = "0.11.2"
diesel = { version = "0.16.0", features = ["sqlite", "deprecated-time", "chrono"] }
diesel_codegen = { version = "0.16.0", features = ["sqlite"] }
time = "0.1.38"
xdg = "2.1.0"
lazy_static = "0.2.8"
chrono = "0.4.0"
rss = { version = "1.1.0", features = ["from_url"]}
# overide diesel's dependancy that would otherwise turn a dotenv feature of
# that rss depends upon
dotenv = "*"

View File

@ -15,14 +15,8 @@ extern crate diesel;
#[macro_use]
extern crate diesel_codegen;
extern crate chrono;
extern crate hyper;
extern crate rayon;
extern crate regex;
extern crate reqwest;
extern crate rfc822_sanitizer;
extern crate rss;
extern crate time;
extern crate xdg;
pub mod dbqueries;
@ -31,33 +25,13 @@ pub mod schema;
pub mod errors {
use reqwest;
use rss;
use chrono;
use hyper;
use time;
use diesel::migrations::RunMigrationsError;
use diesel::result;
use regex;
use std::io;
// use std::option;
// use std::sync;
error_chain! {
foreign_links {
ReqError(reqwest::Error);
IoError(io::Error);
Log(::log::SetLoggerError);
MigrationError(RunMigrationsError);
RSSError(rss::Error);
DieselResultError(result::Error);
ChronoError(chrono::ParseError);
DurationError(time::OutOfRangeError);
HyperError(hyper::error::Error);
RegexError(regex::Error);
// NoneError(option::NoneError);
// MutexPoison(sync::PoisonError);
}
}
}
@ -109,6 +83,7 @@ pub fn init() -> Result<()> {
}
pub fn run_migration_on(connection: &SqliteConnection) -> Result<()> {
info!("Running DB Migrations...");
embedded_migrations::run_with_output(connection, &mut std::io::stdout())?;
Ok(())
}

View File

@ -1,5 +1,4 @@
use reqwest;
use rss::Channel;
use diesel::SaveChangesDsl;
use SqliteConnection;
use reqwest::header::{ETag, LastModified};

View File

@ -6,7 +6,7 @@ use std::fs::{rename, DirBuilder, File};
use std::io::{BufWriter, Read, Write};
use std::path::Path;
use hammond_data::errors::*;
use errors::*;
use hammond_data::dbqueries;
// Adapted from https://github.com/mattgathu/rget .

19
other/src/errors.rs Normal file
View File

@ -0,0 +1,19 @@
use reqwest;
use rss;
use hyper;
use diesel::result;
use hammond_data;
use std::io;
error_chain! {
foreign_links {
ReqError(reqwest::Error);
IoError(io::Error);
Log(::log::SetLoggerError);
RSSError(rss::Error);
DieselResultError(result::Error);
HyperError(hyper::error::Error);
HamDBError(hammond_data::errors::Error);
}
}

View File

@ -2,7 +2,7 @@ use rss::{Channel, Item};
use rfc822_sanitizer::parse_from_rfc2822_with_fallback;
use hammond_data::models;
use hammond_data::errors::*;
use errors::*;
pub fn parse_podcast(chan: &Channel, source_id: i32) -> Result<models::NewPodcast> {
let title = chan.title().to_owned();

View File

@ -9,8 +9,9 @@ use std::sync::{Arc, Mutex};
use hammond_data::schema;
use hammond_data::dbqueries;
use hammond_data::errors::*;
use hammond_data::models::*;
use errors::*;
use feedparser;
fn index_source(con: &SqliteConnection, foo: &NewSource) -> Result<()> {

View File

@ -1,4 +1,4 @@
#![feature(use_extern_macros)]
#![recursion_limit = "1024"]
extern crate diesel;
extern crate hammond_data;
@ -9,7 +9,10 @@ extern crate rayon;
extern crate reqwest;
extern crate rfc822_sanitizer;
extern crate rss;
#[macro_use]
extern crate error_chain;
pub mod feedparser;
pub mod downloader;
pub mod index_feed;
pub mod errors;

View File

@ -12,8 +12,8 @@ extern crate hammond_data;
extern crate other;
use structopt::StructOpt;
use hammond_data::errors::*;
use hammond_data::dbqueries;
use other::errors::*;
use other::downloader;
use other::index_feed;