Improve error handling, canonicalize base path.

This commit is contained in:
Justus Winter 2019-03-06 15:47:52 +01:00
parent d14ba573de
commit 00162cdc94
No known key found for this signature in database
GPG Key ID: 686F55B4AB2B3386
2 changed files with 18 additions and 10 deletions

View File

@ -16,7 +16,7 @@ keys, user IDs and tokens. To run it, supply the absolute path to where you
want the database to live and the absolute path to the template directory.
```bash
cargo run --bin hagrid -- `pwd`/dist
cargo run --bin hagrid -- dist
```
This will spawn a web server listening on port 8080.

View File

@ -70,15 +70,23 @@ pub struct Opt {
}
fn main() {
if let Err(e) = real_main() {
let mut cause = e.as_fail();
eprint!("{}", cause);
while let Some(c) = cause.cause() {
eprint!(":\n {}", c);
cause = c;
}
eprintln!();
::std::process::exit(2);
}
}
fn real_main() -> Result<()> {
use database::{Filesystem, Polymorphic};
let opt = Opt::from_args();
println!("{:#?}", opt);
if !opt.base.is_absolute() {
panic!("Base directory must be absolute");
}
let db = Filesystem::new(opt.base.clone()).unwrap();
web::serve(&opt, Polymorphic::Filesystem(db)).unwrap();
let mut opt = Opt::from_args();
opt.base = opt.base.canonicalize()?;
let db = Filesystem::new(&opt.base)?;
web::serve(&opt, Polymorphic::Filesystem(db))
}