libnyanpasu/clash-nyanpasu · error

unrecognized typed config migration state: existing {} is ne

Error message

unrecognized typed config migration state: existing {} is neither a valid typed clash config nor a recognized legacy runtime config; restore or remove it before retrying

What it means

`typed_file_state` classifies the shared clash config file (valid typed config, legacy runtime config, partial, missing). When the existing file at `ctx.clash_config_path()` parses as neither a valid typed clash config nor a recognized legacy runtime config, the function fails with this guidance message rather than guessing. The `{}` is filled with the full file path.

Source

Thrown at backend/tauri/src/core/migration/modules/typed_config.rs:169

    Typed,
    LegacyRuntime,
    Unrecognized,
}

fn typed_file_state(ctx: &Ctx) -> anyhow::Result<TypedFileState> {
    let application_exists = typed_path_exists(&ctx.application_config_path())?;
    let session_exists = typed_path_exists(&ctx.session_state_path())?;
    let clash_state = classify_shared_clash_file(ctx)?;

    if !application_exists && !session_exists {
        return match clash_state {
            SharedClashFileState::Missing => Ok(TypedFileState::None),
            SharedClashFileState::LegacyRuntime => Ok(TypedFileState::None),
            SharedClashFileState::Typed => partial_typed_file_state(
                vec!["clash-config.yaml"],
                vec!["application.yaml", "session-state.yaml"],
            ),
            SharedClashFileState::Unrecognized => bail!(
                "unrecognized typed config migration state: existing {} is neither \
                 a valid typed clash config nor a recognized legacy runtime config; restore or \
                 remove it before retrying",
                ctx.clash_config_path().display()
            ),
        };
    }

    if application_exists && session_exists {
        match clash_state {
            SharedClashFileState::Typed => {
                validate_existing_typed_files(ctx)?;
                return Ok(TypedFileState::All);
            }
            SharedClashFileState::Missing | SharedClashFileState::LegacyRuntime => {
                validate_existing_application_and_session(ctx)?;
                return Ok(TypedFileState::NeedsClashRepair);
            }

View on GitHub (pinned to f7dbce2997)

Solutions

  1. Inspect the file reported in the error and restore a known-good version from backup.
  2. Delete or move the unrecognized file so migration can regenerate it (after backing it up).
  3. Check for schema changes between app versions and run the appropriate config conversion first.
Defensive patterns

Strategy: validation

Validate before calling

let raw = std::fs::read_to_string(ctx.clash_config_path())?;
let v: serde_yaml::Value = serde_yaml::from_str(&raw)?; // rejects corrupted files pre-migration
if v.get("mode").is_none() && v.get("proxies").is_none() {
    return Err(anyhow::anyhow!("clash config schema unrecognized, restore backup"));
}

Type guard

fn looks_like_typed_or_legacy(v: &serde_yaml::Value) -> bool {
    v.get("mode").is_some() || v.get("proxies").is_some() || v.get("profiles").is_some()
}

Try / catch

match detect_baseline(&mut ctx) {
    Err(e) if e.to_string().contains("unrecognized typed config migration state") => {
        let path = ctx.clash_config_path().to_path_buf();
        std::fs::rename(&path, path.with_extension("bak"))?;
        retry_migration(&mut ctx)?;
    }
    other => other?,
}

Prevention

When it happens

Trigger: Calling `typed_file_state` (via `detect_baseline` or `run`) when the clash config file exists but its content/schema is unrecognized — e.g. corrupted YAML, hand-edited file, or a format from an unknown version.

Common situations: Manual edits or third-party tools rewriting clash-config.yaml; truncated file from a crash mid-write; config from a much older/newer version with an incompatible schema.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of libnyanpasu/clash-nyanpasu@f7dbce2997 (2026-09-08). Data as JSON: /api/errors/000d74640b1be98e. Report an issue: GitHub.