Skip to content

Commit 9170c92

Browse files
authored
feat(core): improve config deserialization error messages (#4607)
1 parent d5e910e commit 9170c92

File tree

4 files changed

+38
-15
lines changed

4 files changed

+38
-15
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"cli.rs": patch
3+
"cli.js": patch
4+
"tauri-build": patch
5+
---
6+
7+
Improve configuration deserialization error messages.

core/tauri-build/src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,15 @@ impl Attributes {
169169
/// This is typically desirable when running inside a build script; see [`try_build`] for no panics.
170170
pub fn build() {
171171
if let Err(error) = try_build(Attributes::default()) {
172-
panic!("error found during tauri-build: {:#?}", error);
172+
let error = format!("{:#}", error);
173+
println!("{}", error);
174+
if error.starts_with("unknown field") {
175+
print!("found an unknown configuration field. This usually means that you are using a CLI version that is newer than `tauri-build` and is incompatible. ");
176+
println!(
177+
"Please try updating the Rust crates by running `cargo update` in the Tauri app folder."
178+
);
179+
}
180+
std::process::exit(1);
173181
}
174182
}
175183

examples/api/src-tauri/Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tooling/cli/src/helpers/config.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,24 @@ fn get_internal(merge_config: Option<&str>, reload: bool) -> crate::Result<Confi
131131
let state = schema.validate(&config);
132132
if !state.errors.is_empty() {
133133
for error in state.errors {
134-
eprintln!(
135-
"`tauri.conf.json` error on `{}`: {}",
136-
error
137-
.get_path()
138-
.chars()
139-
.skip(1)
140-
.collect::<String>()
141-
.replace('/', " > "),
142-
error.get_detail().unwrap_or_else(|| error.get_title()),
143-
);
134+
let path = error
135+
.get_path()
136+
.chars()
137+
.skip(1)
138+
.collect::<String>()
139+
.replace('/', " > ");
140+
if path.is_empty() {
141+
eprintln!(
142+
"`tauri.conf.json` error: {}",
143+
error.get_detail().unwrap_or_else(|| error.get_title()),
144+
);
145+
} else {
146+
eprintln!(
147+
"`tauri.conf.json` error on `{}`: {}",
148+
path,
149+
error.get_detail().unwrap_or_else(|| error.get_title()),
150+
);
151+
}
144152
}
145153
exit(1);
146154
}

0 commit comments

Comments
 (0)