emilk/egui · error

Failed to parse {}: {err}

Error message

Failed to parse {}: {err}

What it means

kittest loads an optional `kittest.toml` config file found near the test (via `find_kittest_toml`). If the file exists but fails TOML deserialization into the config struct (syntax error, unknown/wrong-typed keys), `toml::from_str` returns Err and the test panics with the file path and the TOML error.

Source

Thrown at crates/egui_kittest/src/config.rs:123

            } else {
                format!("{section}.")
            };
            log::warn!(
                "`{prefix}failed_pixel_count_threshold` in kittest.toml is deprecated; \
                 use `{prefix}max_failed_pixels` instead."
            );
        }
    }
}

fn load_config() -> Config {
    if let Ok(config_path) = find_kittest_toml() {
        match std::fs::read_to_string(&config_path) {
            Ok(config_str) => {
                warn_about_deprecated_keys(&config_str);
                match toml::from_str(&config_str) {
                    Ok(config) => config,
                    Err(err) => panic!("Failed to parse {}: {err}", config_path.display()),
                }
            }
            Err(err) => {
                panic!("Failed to read {}: {}", config_path.display(), err);
            }
        }
    } else {
        Config::default()
    }
}

/// Get the global configuration.
///
/// See [`Config::global`] for details.
pub fn config() -> &'static Config {
    Config::global()
}

View on GitHub (pinned to 441971a776)

Solutions

  1. Read the TOML error in the panic — it names the offending line/key — and fix the syntax or value type in that file.
  2. Validate the TOML with any TOML parser/linter (e.g. `taplo`) before committing.
  3. Check for deprecated keys the warning mentions and migrate them to current names.
  4. Ensure value types match the expected schema (numbers unquoted, booleans as true/false, tables with correct nesting).
  5. Temporarily rename/remove kittest.toml to confirm it is the failing file, then rebuild the config incrementally.

Example fix

// kittest.toml
// before
threshold = "0.5"   # string, expected number
snap = "yes"
// after
threshold = 0.5
snap = true
Defensive patterns

Strategy: validation

Validate before calling

// validate kittest.toml before running tests
let raw = std::fs::read_to_string("kittest.toml")?;
let parsed: Result<toml::Value, _> = toml::from_str(&raw);
assert!(parsed.is_ok(), "kittest.toml invalid: {:?}", parsed.err());

Try / catch

// when loading configs yourself, avoid panicking:
match toml::from_str::<KittestConfig>(&raw) {
    Ok(cfg) => cfg,
    Err(err) => { eprintln!("bad kittest.toml: {err}"); KittestConfig::default() }
}

Prevention

When it happens

Trigger: Having a `kittest.toml` with invalid TOML syntax (unclosed string/table) or a field whose type doesn't match the config struct (e.g. `threshold = "0.5"` instead of a number), or a misspelled key not handled by serde (unless unknown keys are allowed).

Common situations: Hand-editing kittest.toml and introducing a typo; upgrading kittest where config keys were renamed/deprecated (note `warn_about_deprecated_keys` runs first, but removed keys still break parsing); copying a config from docs with different types.

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 emilk/egui@441971a776 (2026-09-12). Data as JSON: /api/errors/10f3515aa0860680. Report an issue: GitHub.