Skip to content

Commit 8201b41

Browse files
authored
Merge pull request #1555 from joshrotenberg/exit_serve_if_panic
Use std::panic::set_hook to exit serve thread if serving fails
2 parents 836546c + fcf8f93 commit 8201b41

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/cmd/serve.rs

+7
Original file line numberDiff line numberDiff line change
@@ -161,5 +161,12 @@ async fn serve(
161161
let fallback_route = warp::fs::file(build_dir.join(file_404))
162162
.map(|reply| warp::reply::with_status(reply, warp::http::StatusCode::NOT_FOUND));
163163
let routes = livereload.or(book_route).or(fallback_route);
164+
165+
std::panic::set_hook(Box::new(move |panic_info| {
166+
// exit if serve panics
167+
error!("Unable to serve: {}", panic_info);
168+
std::process::exit(1);
169+
}));
170+
164171
warp::serve(routes).run(address).await;
165172
}

0 commit comments

Comments
 (0)