Browse Source

improve error formatting

master
Astro 3 years ago
parent
commit
3cd57801c8
  1. 18
      src/main.rs

18
src/main.rs

@ -171,7 +171,7 @@ impl Resources {
let (etag, last_modified, events) =
self.worker_fetch(&cal_id, &cal_opts, etag, last_modified)
.map_err(|e| {
let msg = format!("{:?}", e);
let msg = format!("{}", e);
println!("[{}] {}", cal_id, msg);
let _ = diesel::update(calendars)
.filter(schema::calendars::dsl::id.eq(cal_id.clone()))
@ -211,7 +211,7 @@ impl Resources {
let mut done = false;
while ! done {
done = self.worker_job(&db)
.map_err(|e| println!("{:?}", e))
.map_err(|e| println!("{}", e))
.unwrap_or(false);
}
Ok(())
@ -251,6 +251,18 @@ impl From<std::io::Error> for Error {
}
}
impl std::fmt::Display for Error {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
match self {
Error::DbConnection(e) => e.fmt(fmt),
Error::Db(e) => e.fmt(fmt),
Error::Http(e) => e.fmt(fmt),
Error::Io(e) => e.fmt(fmt),
Error::Message(e) => e.fmt(fmt),
}
}
}
fn main() {
let config_file = read_to_string("config.yaml")
.expect("config.yaml");
@ -267,7 +279,7 @@ fn main() {
let workers: Vec<_> = (0..cpus)
.map(|_| s.spawn(|_| {
res.worker_loop()
.map_err(|e| println!("{:?}", e))
.map_err(|e| println!("{}", e))
}))
.collect();
for worker in workers.into_iter() {

Loading…
Cancel
Save