Skip to content

Commit cc186c7

Browse files
fix(cli): keep dev watcher alive if config is incorrect, closes #5173 (#5495)
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
1 parent 79dd6e1 commit cc186c7

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

.changes/cli-dev-alive-on-error.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"cli.rs": "patch"
3+
---
4+
5+
Keep `tauri dev` watcher alive when the configuration is invalid.

tooling/cli/src/helpers/config.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use anyhow::Context;
66
use json_patch::merge;
7+
use log::error;
78
use once_cell::sync::Lazy;
89
use serde_json::Value as JsonValue;
910

@@ -141,12 +142,14 @@ fn get_internal(merge_config: Option<&str>, reload: bool) -> crate::Result<Confi
141142
for error in errors {
142143
let path = error.instance_path.clone().into_vec().join(" > ");
143144
if path.is_empty() {
144-
eprintln!("`{config_file_name}` error: {}", error);
145+
error!("`{}` error: {}", config_file_name, error);
145146
} else {
146-
eprintln!("`{config_file_name}` error on `{}`: {}", path, error);
147+
error!("`{}` error on `{}`: {}", config_file_name, path, error);
147148
}
148149
}
149-
exit(1);
150+
if !reload {
151+
exit(1);
152+
}
150153
}
151154
}
152155

tooling/cli/src/interface/rust.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use anyhow::Context;
2222
#[cfg(target_os = "linux")]
2323
use heck::ToKebabCase;
2424
use ignore::gitignore::{Gitignore, GitignoreBuilder};
25-
use log::{debug, info};
25+
use log::{debug, error, info};
2626
use notify::RecursiveMode;
2727
use notify_debouncer_mini::new_debouncer;
2828
use serde::Deserialize;
@@ -457,10 +457,21 @@ impl Rust {
457457

458458
if !ignore_matcher.is_ignore(&event_path, event_path.is_dir()) {
459459
if is_configuration_file(&event_path) {
460-
info!("Tauri configuration changed. Rewriting manifest...");
461-
let config = reload_config(options.config.as_deref())?;
462-
self.app_settings.manifest =
463-
rewrite_manifest(config.lock().unwrap().as_ref().unwrap())?;
460+
match reload_config(options.config.as_deref()) {
461+
Ok(config) => {
462+
info!("Tauri configuration changed. Rewriting manifest...");
463+
self.app_settings.manifest =
464+
rewrite_manifest(config.lock().unwrap().as_ref().unwrap())?
465+
}
466+
Err(err) => {
467+
let p = process.lock().unwrap();
468+
let is_building_app = p.app_child.lock().unwrap().is_none();
469+
if is_building_app {
470+
p.kill().with_context(|| "failed to kill app process")?;
471+
}
472+
error!("{}", err);
473+
}
474+
}
464475
} else {
465476
info!(
466477
"File {} changed. Rebuilding application...",

0 commit comments

Comments
 (0)