Skip to content

Commit

Permalink
Merge pull request #105 from Demonthos/hot-reloading-resilient
Browse files Browse the repository at this point in the history
Log io errors instead of panicking for hot reloading
  • Loading branch information
jkelleyrtp authored Feb 22, 2023
2 parents 39b8012 + bfbda51 commit 6c2a51e
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,11 @@ pub async fn startup_hot_reload(ip: String, port: u16, config: CrateConfig) -> R

let dist_path = config.out_dir.clone();
let (reload_tx, _) = broadcast::channel(100);
let file_map = Arc::new(Mutex::new(FileMap::<HtmlCtx>::new(
config.crate_dir.clone(),
)));
let FileMapBuildResult { map, errors } = FileMap::<HtmlCtx>::create(config.crate_dir.clone())?;
for err in errors {
log::error!("{}", err);
}
let file_map = Arc::new(Mutex::new(map));
let build_manager = Arc::new(BuildManager {
config: config.clone(),
reload_tx: reload_tx.clone(),
Expand Down Expand Up @@ -185,10 +187,10 @@ pub async fn startup_hot_reload(ip: String, port: u16, config: CrateConfig) -> R
let mut map = file_map.lock().unwrap();

match map.update_rsx(&path, &crate_dir) {
UpdateResult::UpdatedRsx(msgs) => {
Ok(UpdateResult::UpdatedRsx(msgs)) => {
messages.extend(msgs);
}
UpdateResult::NeedsRebuild => {
Ok(UpdateResult::NeedsRebuild) => {
match build_manager.rebuild() {
Ok(res) => {
print_console_info(
Expand All @@ -208,6 +210,9 @@ pub async fn startup_hot_reload(ip: String, port: u16, config: CrateConfig) -> R
}
return;
}
Err(err) => {
log::error!("{}", err);
}
}
}
for msg in messages {
Expand All @@ -222,12 +227,12 @@ pub async fn startup_hot_reload(ip: String, port: u16, config: CrateConfig) -> R
.unwrap();

for sub_path in allow_watch_path {
watcher
.watch(
&config.crate_dir.join(sub_path),
notify::RecursiveMode::Recursive,
)
.unwrap();
if let Err(err) = watcher.watch(
&config.crate_dir.join(&sub_path),
notify::RecursiveMode::Recursive,
) {
log::error!("error watching {sub_path:?}: \n{}", err);
}
}

// start serve dev-server at 0.0.0.0:8080
Expand Down

0 comments on commit 6c2a51e

Please sign in to comment.