{"record":{"id":"8d651e79d483f3b6","repo":"tauri-apps/tauri","slug":"failed-to-canonicalize-global-api-script-path","errorCode":null,"errorMessage":"failed to canonicalize global API script path","messagePattern":"failed to canonicalize global API script path","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tauri-utils/src/plugin.rs","lineNumber":27,"sourceCode":"#[cfg(any(feature = \"build\", feature = \"build-2\"))]\nmod build {\n  use std::{\n    env::vars_os,\n    fs,\n    path::{Path, PathBuf},\n  };\n\n  const GLOBAL_API_SCRIPT_PATH_KEY: &str = \"GLOBAL_API_SCRIPT_PATH\";\n  /// Known file name of the file that contains an array with the path of all API scripts defined with [`define_global_api_script_path`].\n  pub const GLOBAL_API_SCRIPT_FILE_LIST_PATH: &str = \"__global-api-script.js\";\n\n  /// Defines the path to the global API script using Cargo instructions.\n  pub fn define_global_api_script_path(path: &Path) {\n    println!(\n      \"cargo:{GLOBAL_API_SCRIPT_PATH_KEY}={}\",\n      path\n        .canonicalize()\n        .expect(\"failed to canonicalize global API script path\")\n        .display()\n    )\n  }\n\n  /// Collects the path of all the global API scripts defined with [`define_global_api_script_path`]\n  /// and saves them to the out dir with filename [`GLOBAL_API_SCRIPT_FILE_LIST_PATH`].\n  ///\n  /// `tauri_global_scripts` is only used in Tauri's monorepo for the examples to work\n  /// since they don't have a build script to run `tauri-build` and pull in the deps env vars\n  pub fn save_global_api_scripts_paths(out_dir: &Path, mut tauri_global_scripts: Option<PathBuf>) {\n    let mut scripts = Vec::new();\n\n    for (key, value) in vars_os() {\n      let key = key.to_string_lossy();\n\n      if key == format!(\"DEP_TAURI_{GLOBAL_API_SCRIPT_PATH_KEY}\") {\n        tauri_global_scripts = Some(PathBuf::from(value));\n      } else if key.starts_with(\"DEP_\") && key.ends_with(GLOBAL_API_SCRIPT_PATH_KEY) {","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/tauri-apps/tauri/blob/460ec35447493200d64290dd7f015d5a91d0fd58/crates/tauri-utils/src/plugin.rs#L9-L45","documentation":"`define_global_api_script_path` is a build-script helper that canonicalizes the given path (resolving symlinks and making it absolute) before emitting it to Cargo. It panics with this message when `Path::canonicalize` fails — the path does not exist or cannot be resolved (permissions, broken symlink, non-UTF8/OS error).","triggerScenarios":"Calling `tauri_utils::plugin::define_global_api_script_path(path)` in a build script with a path that does not exist yet (file not generated before this call), a wrong relative path from the crate root, or a broken symlink.","commonSituations":"Build scripts calling the helper before the global API script is generated; typos in the script path; running the build from a different working directory than expected; symlink issues on CI.","solutions":["Ensure the global API script file exists (generate/write it) before calling `define_global_api_script_path`","Verify the path is correct relative to the build script's working directory (`CARGO_MANIFEST_DIR`)","Check symlink targets exist and the file is readable","Join the path onto `PathBuf::from(env::var(\"CARGO_MANIFEST_DIR\"))` to make it unambiguous"],"exampleFix":"// before\ndefine_global_api_script_path(Path::new(\"scripts/api.js\"));\n// after\nlet p = PathBuf::from(std::env::var(\"CARGO_MANIFEST_DIR\").unwrap()).join(\"scripts/api.js\");\nassert!(p.exists(), \"api script missing: {}\", p.display());\ndefine_global_api_script_path(&p);","handlingStrategy":"validation","validationCode":"let p = PathBuf::from(env::var(\"CARGO_MANIFEST_DIR\").unwrap()).join(rel);\nassert!(p.is_file(), \"global API script not found: {}\", p.display());","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Generate the script file before registering it in the build script","Anchor relative paths on CARGO_MANIFEST_DIR","Confirm symlinks resolve on CI"],"tags":["build-script","filesystem","panic","path-canonicalization","tauri"],"backgroundTag":"file-not-found","analyzedSha":"460ec35447493200d64290dd7f015d5a91d0fd58","analyzedAt":"2026-09-18T23:55:51.277Z","contentChangedAt":"2026-09-18T23:55:51.277Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}