From 9170c9207044fa561535f624916dfdbaa41ff79d Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Wed, 6 Jul 2022 10:33:45 -0300 Subject: [PATCH] feat(core): improve config deserialization error messages (#4607) --- .changes/improve-config-error-message.md | 7 ++++++ core/tauri-build/src/lib.rs | 10 ++++++++- examples/api/src-tauri/Cargo.lock | 8 +++---- tooling/cli/src/helpers/config.rs | 28 +++++++++++++++--------- 4 files changed, 38 insertions(+), 15 deletions(-) create mode 100644 .changes/improve-config-error-message.md diff --git a/.changes/improve-config-error-message.md b/.changes/improve-config-error-message.md new file mode 100644 index 000000000..c49f2cc23 --- /dev/null +++ b/.changes/improve-config-error-message.md @@ -0,0 +1,7 @@ +--- +"cli.rs": patch +"cli.js": patch +"tauri-build": patch +--- + +Improve configuration deserialization error messages. diff --git a/core/tauri-build/src/lib.rs b/core/tauri-build/src/lib.rs index 5e2ecff0f..aa50b2080 100644 --- a/core/tauri-build/src/lib.rs +++ b/core/tauri-build/src/lib.rs @@ -169,7 +169,15 @@ impl Attributes { /// This is typically desirable when running inside a build script; see [`try_build`] for no panics. pub fn build() { if let Err(error) = try_build(Attributes::default()) { - panic!("error found during tauri-build: {:#?}", error); + let error = format!("{:#}", error); + println!("{}", error); + if error.starts_with("unknown field") { + 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. "); + println!( + "Please try updating the Rust crates by running `cargo update` in the Tauri app folder." + ); + } + std::process::exit(1); } } diff --git a/examples/api/src-tauri/Cargo.lock b/examples/api/src-tauri/Cargo.lock index 00c1b8194..2afcba228 100644 --- a/examples/api/src-tauri/Cargo.lock +++ b/examples/api/src-tauri/Cargo.lock @@ -2532,9 +2532,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.5.6" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d83f127d94bdbcda4c8cc2e50f6f84f4b611f69c902699ca385a39c3a75f9ff1" +checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" dependencies = [ "aho-corasick", "memchr", @@ -2552,9 +2552,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.26" +version = "0.6.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64" +checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" [[package]] name = "remove_dir_all" diff --git a/tooling/cli/src/helpers/config.rs b/tooling/cli/src/helpers/config.rs index 03c7f227f..7bbf63d80 100644 --- a/tooling/cli/src/helpers/config.rs +++ b/tooling/cli/src/helpers/config.rs @@ -131,16 +131,24 @@ fn get_internal(merge_config: Option<&str>, reload: bool) -> crate::Result() - .replace('/', " > "), - error.get_detail().unwrap_or_else(|| error.get_title()), - ); + let path = error + .get_path() + .chars() + .skip(1) + .collect::() + .replace('/', " > "); + if path.is_empty() { + eprintln!( + "`tauri.conf.json` error: {}", + error.get_detail().unwrap_or_else(|| error.get_title()), + ); + } else { + eprintln!( + "`tauri.conf.json` error on `{}`: {}", + path, + error.get_detail().unwrap_or_else(|| error.get_title()), + ); + } } exit(1); }