Эх сурвалжийг харах

feat(core): improve config deserialization error messages (#4607)

Lucas Fernandes Nogueira 3 жил өмнө
parent
commit
9170c92070

+ 7 - 0
.changes/improve-config-error-message.md

@@ -0,0 +1,7 @@
+---
+"cli.rs": patch
+"cli.js": patch
+"tauri-build": patch
+---
+
+Improve configuration deserialization error messages.

+ 9 - 1
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);
   }
 }
 

+ 4 - 4
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"

+ 18 - 10
tooling/cli/src/helpers/config.rs

@@ -131,16 +131,24 @@ fn get_internal(merge_config: Option<&str>, reload: bool) -> crate::Result<Confi
   let state = schema.validate(&config);
   if !state.errors.is_empty() {
     for error in state.errors {
-      eprintln!(
-        "`tauri.conf.json` error on `{}`: {}",
-        error
-          .get_path()
-          .chars()
-          .skip(1)
-          .collect::<String>()
-          .replace('/', " > "),
-        error.get_detail().unwrap_or_else(|| error.get_title()),
-      );
+      let path = error
+        .get_path()
+        .chars()
+        .skip(1)
+        .collect::<String>()
+        .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);
   }