tauri-apps/tauri · error

failed to read plugin global API script paths

Error message

failed to read plugin global API script paths

What it means

`read_global_api_scripts` reads the previously saved file list from `GLOBAL_API_SCRIPT_FILE_LIST_PATH` with `fs::read_to_string` and panics with this message if the read fails. Note the existence check only guards a missing file; I/O errors (permissions, races where the file vanishes between `exists()` and read) trigger the panic.

Solutions

  1. Verify the file list is readable and a regular file in the given `out_dir` before calling
  2. Do a clean rebuild (`cargo clean`) to regenerate a valid out dir
  3. Fix permissions on the build output directory
  4. Avoid concurrent builds sharing the same OUT_DIR
Defensive patterns

Strategy: validation

Validate before calling

let p = out_dir.join(GLOBAL_API_SCRIPT_FILE_LIST_PATH);
if !p.is_file() {
  // treat as missing instead of reading
  return None;
}

Prevention

When it happens

Trigger: Calling `read_global_api_scripts` with an `out_dir` pointing at a location where the file list exists but is unreadable: wrong permissions, the path being a directory, or a TOCTOU race where the file is deleted after the `exists()` check.

Common situations: Mixing build outputs from different workspaces; CI cache restoring a partially written out dir; permission-restricted build directories; concurrent builds racing on the same OUT_DIR.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of tauri-apps/tauri@460ec35447 (2026-09-18). Data as JSON: /api/errors/b70d7c5eb057b97f. Report an issue: GitHub.

Appendix: source

Thrown at crates/tauri-utils/src/plugin.rs:70

      scripts.insert(0, tauri_global_scripts);
    }

    fs::write(
      out_dir.join(GLOBAL_API_SCRIPT_FILE_LIST_PATH),
      serde_json::to_string(&scripts).expect("failed to serialize global API script paths"),
    )
    .expect("failed to write global API script");
  }

  /// Read global api scripts from [`GLOBAL_API_SCRIPT_FILE_LIST_PATH`]
  pub fn read_global_api_scripts(out_dir: &Path) -> Option<Vec<String>> {
    let global_scripts_path = out_dir.join(GLOBAL_API_SCRIPT_FILE_LIST_PATH);
    if !global_scripts_path.exists() {
      return None;
    }

    let global_scripts_str = fs::read_to_string(global_scripts_path)
      .expect("failed to read plugin global API script paths");
    let global_scripts = serde_json::from_str::<Vec<PathBuf>>(&global_scripts_str)
      .expect("failed to parse plugin global API script paths");

    Some(
      global_scripts
        .into_iter()
        .map(|p| {
          fs::read_to_string(&p).unwrap_or_else(|e| {
            panic!(
              "failed to read plugin global API script {}: {e}",
              p.display()
            )
          })
        })
        .collect(),
    )
  }
}

View on GitHub (pinned to 460ec35447)