Error handling cleanup.
This commit is contained in:
parent
f25ce64e34
commit
bf9e544a2b
@ -4,24 +4,13 @@ version = "0.1.0"
|
|||||||
authors = ["Jordan Petridis <jordanpetridis@protonmail.com>"]
|
authors = ["Jordan Petridis <jordanpetridis@protonmail.com>"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rfc822_sanitizer = "0.3.0"
|
|
||||||
rayon = "0.8.2"
|
rayon = "0.8.2"
|
||||||
regex = "0.2"
|
|
||||||
error-chain = "0.11.0"
|
error-chain = "0.11.0"
|
||||||
structopt = "0.1.0"
|
|
||||||
structopt-derive = "0.1.0"
|
|
||||||
log = "0.3.8"
|
log = "0.3.8"
|
||||||
loggerv = "0.3.0"
|
loggerv = "0.3.0"
|
||||||
reqwest = "0.7.3"
|
reqwest = "0.7.3"
|
||||||
hyper = "0.11.2"
|
|
||||||
diesel = { version = "0.16.0", features = ["sqlite", "deprecated-time", "chrono"] }
|
diesel = { version = "0.16.0", features = ["sqlite", "deprecated-time", "chrono"] }
|
||||||
diesel_codegen = { version = "0.16.0", features = ["sqlite"] }
|
diesel_codegen = { version = "0.16.0", features = ["sqlite"] }
|
||||||
time = "0.1.38"
|
|
||||||
xdg = "2.1.0"
|
xdg = "2.1.0"
|
||||||
lazy_static = "0.2.8"
|
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 = "*"
|
|
||||||
|
|
||||||
|
|||||||
@ -15,14 +15,8 @@ extern crate diesel;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate diesel_codegen;
|
extern crate diesel_codegen;
|
||||||
|
|
||||||
extern crate chrono;
|
|
||||||
extern crate hyper;
|
|
||||||
extern crate rayon;
|
extern crate rayon;
|
||||||
extern crate regex;
|
|
||||||
extern crate reqwest;
|
extern crate reqwest;
|
||||||
extern crate rfc822_sanitizer;
|
|
||||||
extern crate rss;
|
|
||||||
extern crate time;
|
|
||||||
extern crate xdg;
|
extern crate xdg;
|
||||||
|
|
||||||
pub mod dbqueries;
|
pub mod dbqueries;
|
||||||
@ -31,33 +25,13 @@ pub mod schema;
|
|||||||
|
|
||||||
pub mod errors {
|
pub mod errors {
|
||||||
|
|
||||||
use reqwest;
|
|
||||||
use rss;
|
|
||||||
use chrono;
|
|
||||||
use hyper;
|
|
||||||
use time;
|
|
||||||
use diesel::migrations::RunMigrationsError;
|
use diesel::migrations::RunMigrationsError;
|
||||||
use diesel::result;
|
use diesel::result;
|
||||||
use regex;
|
|
||||||
|
|
||||||
use std::io;
|
|
||||||
// use std::option;
|
|
||||||
// use std::sync;
|
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
foreign_links {
|
foreign_links {
|
||||||
ReqError(reqwest::Error);
|
|
||||||
IoError(io::Error);
|
|
||||||
Log(::log::SetLoggerError);
|
|
||||||
MigrationError(RunMigrationsError);
|
MigrationError(RunMigrationsError);
|
||||||
RSSError(rss::Error);
|
|
||||||
DieselResultError(result::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<()> {
|
pub fn run_migration_on(connection: &SqliteConnection) -> Result<()> {
|
||||||
|
info!("Running DB Migrations...");
|
||||||
embedded_migrations::run_with_output(connection, &mut std::io::stdout())?;
|
embedded_migrations::run_with_output(connection, &mut std::io::stdout())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
use reqwest;
|
use reqwest;
|
||||||
use rss::Channel;
|
|
||||||
use diesel::SaveChangesDsl;
|
use diesel::SaveChangesDsl;
|
||||||
use SqliteConnection;
|
use SqliteConnection;
|
||||||
use reqwest::header::{ETag, LastModified};
|
use reqwest::header::{ETag, LastModified};
|
||||||
|
|||||||
@ -6,7 +6,7 @@ use std::fs::{rename, DirBuilder, File};
|
|||||||
use std::io::{BufWriter, Read, Write};
|
use std::io::{BufWriter, Read, Write};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use hammond_data::errors::*;
|
use errors::*;
|
||||||
use hammond_data::dbqueries;
|
use hammond_data::dbqueries;
|
||||||
|
|
||||||
// Adapted from https://github.com/mattgathu/rget .
|
// Adapted from https://github.com/mattgathu/rget .
|
||||||
|
|||||||
19
other/src/errors.rs
Normal file
19
other/src/errors.rs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,7 +2,7 @@ use rss::{Channel, Item};
|
|||||||
use rfc822_sanitizer::parse_from_rfc2822_with_fallback;
|
use rfc822_sanitizer::parse_from_rfc2822_with_fallback;
|
||||||
|
|
||||||
use hammond_data::models;
|
use hammond_data::models;
|
||||||
use hammond_data::errors::*;
|
use errors::*;
|
||||||
|
|
||||||
pub fn parse_podcast(chan: &Channel, source_id: i32) -> Result<models::NewPodcast> {
|
pub fn parse_podcast(chan: &Channel, source_id: i32) -> Result<models::NewPodcast> {
|
||||||
let title = chan.title().to_owned();
|
let title = chan.title().to_owned();
|
||||||
|
|||||||
@ -9,8 +9,9 @@ use std::sync::{Arc, Mutex};
|
|||||||
|
|
||||||
use hammond_data::schema;
|
use hammond_data::schema;
|
||||||
use hammond_data::dbqueries;
|
use hammond_data::dbqueries;
|
||||||
use hammond_data::errors::*;
|
|
||||||
use hammond_data::models::*;
|
use hammond_data::models::*;
|
||||||
|
|
||||||
|
use errors::*;
|
||||||
use feedparser;
|
use feedparser;
|
||||||
|
|
||||||
fn index_source(con: &SqliteConnection, foo: &NewSource) -> Result<()> {
|
fn index_source(con: &SqliteConnection, foo: &NewSource) -> Result<()> {
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#![feature(use_extern_macros)]
|
#![recursion_limit = "1024"]
|
||||||
|
|
||||||
extern crate diesel;
|
extern crate diesel;
|
||||||
extern crate hammond_data;
|
extern crate hammond_data;
|
||||||
@ -9,7 +9,10 @@ extern crate rayon;
|
|||||||
extern crate reqwest;
|
extern crate reqwest;
|
||||||
extern crate rfc822_sanitizer;
|
extern crate rfc822_sanitizer;
|
||||||
extern crate rss;
|
extern crate rss;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate error_chain;
|
||||||
|
|
||||||
pub mod feedparser;
|
pub mod feedparser;
|
||||||
pub mod downloader;
|
pub mod downloader;
|
||||||
pub mod index_feed;
|
pub mod index_feed;
|
||||||
|
pub mod errors;
|
||||||
@ -12,8 +12,8 @@ extern crate hammond_data;
|
|||||||
extern crate other;
|
extern crate other;
|
||||||
|
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
use hammond_data::errors::*;
|
|
||||||
use hammond_data::dbqueries;
|
use hammond_data::dbqueries;
|
||||||
|
use other::errors::*;
|
||||||
use other::downloader;
|
use other::downloader;
|
||||||
use other::index_feed;
|
use other::index_feed;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user