Skip to content

Commit e463025

Browse files
authored
fix(cli): restore working directory when config parsing fails (#16114)
1 parent fe1aa30 commit e463025

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

‎.changes/cli-config-cwd-restore.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-cli": patch:bug
3+
"@tauri-apps/cli": patch:bug
4+
---
5+
6+
Fix the CLI's working directory being left changed to the config directory when the Tauri configuration fails to parse, for example when `tauri dev` reloads an invalid config.

‎crates/tauri-cli/src/helpers/config.rs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,10 @@ fn load_config(
195195
// so we actually need to change the current working directory here
196196
let current_dir = current_dir().context("failed to resolve current directory")?;
197197
set_current_dir(config_path.parent().unwrap()).context("failed to set current directory")?;
198-
let config: Config = serde_json::from_value(config).context("failed to parse config")?;
199-
// revert to previous working directory
198+
let config: serde_json::Result<Config> = serde_json::from_value(config);
199+
// revert to previous working directory, even if parsing failed
200200
set_current_dir(current_dir).context("failed to set current directory")?;
201+
let config = config.context("failed to parse config")?;
201202

202203
for (plugin, conf) in &config.plugins.0 {
203204
unsafe {

0 commit comments

Comments
 (0)