Skip to content

Commit

Permalink
fix(cli): keep dev watcher alive if config is incorrect, closes #5173 (
Browse files Browse the repository at this point in the history
…#5495)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
  • Loading branch information
amrbashir and lucasfernog authored Oct 27, 2022
1 parent 79dd6e1 commit cc186c7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changes/cli-dev-alive-on-error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"cli.rs": "patch"
---

Keep `tauri dev` watcher alive when the configuration is invalid.
9 changes: 6 additions & 3 deletions tooling/cli/src/helpers/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use anyhow::Context;
use json_patch::merge;
use log::error;
use once_cell::sync::Lazy;
use serde_json::Value as JsonValue;

Expand Down Expand Up @@ -141,12 +142,14 @@ fn get_internal(merge_config: Option<&str>, reload: bool) -> crate::Result<Confi
for error in errors {
let path = error.instance_path.clone().into_vec().join(" > ");
if path.is_empty() {
eprintln!("`{config_file_name}` error: {}", error);
error!("`{}` error: {}", config_file_name, error);
} else {
eprintln!("`{config_file_name}` error on `{}`: {}", path, error);
error!("`{}` error on `{}`: {}", config_file_name, path, error);
}
}
exit(1);
if !reload {
exit(1);
}
}
}

Expand Down
21 changes: 16 additions & 5 deletions tooling/cli/src/interface/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use anyhow::Context;
#[cfg(target_os = "linux")]
use heck::ToKebabCase;
use ignore::gitignore::{Gitignore, GitignoreBuilder};
use log::{debug, info};
use log::{debug, error, info};
use notify::RecursiveMode;
use notify_debouncer_mini::new_debouncer;
use serde::Deserialize;
Expand Down Expand Up @@ -457,10 +457,21 @@ impl Rust {

if !ignore_matcher.is_ignore(&event_path, event_path.is_dir()) {
if is_configuration_file(&event_path) {
info!("Tauri configuration changed. Rewriting manifest...");
let config = reload_config(options.config.as_deref())?;
self.app_settings.manifest =
rewrite_manifest(config.lock().unwrap().as_ref().unwrap())?;
match reload_config(options.config.as_deref()) {
Ok(config) => {
info!("Tauri configuration changed. Rewriting manifest...");
self.app_settings.manifest =
rewrite_manifest(config.lock().unwrap().as_ref().unwrap())?
}
Err(err) => {
let p = process.lock().unwrap();
let is_building_app = p.app_child.lock().unwrap().is_none();
if is_building_app {
p.kill().with_context(|| "failed to kill app process")?;
}
error!("{}", err);
}
}
} else {
info!(
"File {} changed. Rebuilding application...",
Expand Down

0 comments on commit cc186c7

Please sign in to comment.