tw93/Pake · critical

Failed to parse tauri config

Error message

Failed to parse tauri config

What it means

get_pake_config also deserializes the embedded tauri.conf.json into tauri::Config with serde_json, panicking with this expect message if it fails. Because the file is compiled in, an invalid tauri.conf.json breaks the app before any window is created.

Solutions

  1. Validate tauri.conf.json against the Tauri v2 config schema (tauri CLI: `cargo tauri dev` reports the schema error).
  2. Fix JSON syntax or field types (check identifier, bundle, and windows sections).
  3. If the file was mutated by a build, restore it from git and re-run the pake CLI.

Example fix

// before (tauri.conf.json)
{ "identifier": "" }
// after
{ "identifier": "com.example.pakeapp" }
Defensive patterns

Strategy: validation

Validate before calling

const conf = JSON.parse(fs.readFileSync('src-tauri/tauri.conf.json'));
if (typeof conf.identifier !== 'string' || conf.identifier.length === 0) throw new Error('tauri.conf.json identifier missing');

Type guard

const looksLikeTauriConfig = (c) => typeof c === 'object' && c !== null && typeof c.identifier === 'string';

Try / catch

// dev-time guard
try { JSON.parse(fs.readFileSync('src-tauri/tauri.conf.json', 'utf8')); } catch (e) { console.error('tauri.conf.json invalid:', e.message); process.exit(1); }

Prevention

When it happens

Trigger: tauri.conf.json (or .pake/tauri.conf.json under cli-build) contains JSON syntax errors or values violating Tauri v2's Config schema (e.g. bad bundle identifier, wrong types in windows options).

Common situations: Hand edits for custom icons/identifiers that break the schema; a Tauri major-version upgrade changing required fields; merge conflicts resolved incorrectly in tauri.conf.json.

Understand the failure class

Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.

Related errors


AI-assisted analysis of tw93/Pake@c8fe8a3f1a (2026-09-20). Data as JSON: /api/errors/7e389711e947489a. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/src/util.rs:18

use crate::app::config::PakeConfig;
use crate::app::window::MultiWindowState;
use std::env;
use std::path::{Path, PathBuf};
use tauri::{AppHandle, Config, Manager, WebviewWindow};

pub fn get_pake_config() -> (PakeConfig, Config) {
    #[cfg(feature = "cli-build")]
    let pake_config: PakeConfig = serde_json::from_str(include_str!("../.pake/pake.json"))
        .expect("Failed to parse pake config");

    #[cfg(not(feature = "cli-build"))]
    let pake_config: PakeConfig =
        serde_json::from_str(include_str!("../pake.json")).expect("Failed to parse pake config");

    #[cfg(feature = "cli-build")]
    let tauri_config: Config = serde_json::from_str(include_str!("../.pake/tauri.conf.json"))
        .expect("Failed to parse tauri config");

    #[cfg(not(feature = "cli-build"))]
    let tauri_config: Config = serde_json::from_str(include_str!("../tauri.conf.json"))
        .expect("Failed to parse tauri config");

    (pake_config, tauri_config)
}

pub fn get_data_dir(app: &AppHandle, package_name: String) -> std::io::Result<PathBuf> {
    let data_dir = app
        .path()
        .config_dir()
        .map_err(|err| {
            std::io::Error::new(
                std::io::ErrorKind::NotFound,
                format!("Failed to resolve config dir: {err}"),
            )
        })?

View on GitHub (pinned to c8fe8a3f1a)