Improve error handling, canonicalize base path.
This commit is contained in:
parent
d14ba573de
commit
00162cdc94
|
@ -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.
|
||||
|
|
26
src/main.rs
26
src/main.rs
|
@ -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))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue