{"record":{"id":"3d7c725c4e53214b","repo":"starship/starship","slug":"failed-to-load-starship-config","errorCode":null,"errorMessage":"Failed to load starship config","messagePattern":"Failed to load starship config","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/configure.rs","lineNumber":238,"sourceCode":"\n    values.insert(key, new_value);\n    Ok(())\n}\n\npub fn get_configuration(context: &Context) -> toml::Table {\n    let starship_config = StarshipConfig::initialize(context.get_config_path_os().as_deref());\n\n    starship_config.config.unwrap_or_default()\n}\n\npub fn get_configuration_edit(context: &Context) -> DocumentMut {\n    let config_file_path = context.get_config_path_os();\n    let toml_content = StarshipConfig::read_config_content_as_str(config_file_path.as_deref());\n\n    toml_content\n        .unwrap_or_default()\n        .parse::<DocumentMut>()\n        .expect(\"Failed to load starship config\")\n}\n\npub fn write_configuration(context: &Context, doc: &DocumentMut) {\n    let Some(config_path) = context.get_config_path_os() else {\n        eprintln!(\"config path required to write configuration\");\n        process::exit(1);\n    };\n\n    let config_path = PathBuf::from(config_path);\n\n    if let Err(e) = crate::utils::write_file_atomic(config_path, doc.to_string(), true) {\n        eprintln!(\"Unable to write configuration: {e}\");\n        process::exit(1);\n    }\n}\n\npub fn edit_configuration(\n    context: &Context,","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/starship/starship/blob/c13a634f3925a046826c26bf992ec6cf9f48725c/src/configure.rs#L220-L256","documentation":"This panic comes from get_configuration_edit() in src/configure.rs. It reads the file at STARSHIP_CONFIG (or ~/.config/starship.toml), falls back to an empty string when the file is missing, and then calls toml_edit's DocumentMut::parse. parse() returns Err when the file content is not valid TOML (duplicate keys, unclosed strings/brackets, bare values, wrong types), and .expect() turns that Err into a process abort with the message 'Failed to load starship config'.","triggerScenarios":"Calling `starship config` (or any code path that calls get_configuration_edit) while the config file exists but contains a TOML syntax error. A missing file does NOT trigger it (unwrap_or_default yields an empty string, which parses fine) - only malformed TOML content does.","commonSituations":"Hand-editing starship.toml and leaving an unterminated quote or trailing comma; pasting a preset that got truncated; using single quotes instead of TOML-style strings; a plugin or editor writing partial content; tabs/copy-paste introducing smart quotes; a failed atomic write leaving a partial file.","solutions":["Validate the file with an external TOML linter or `tomlcheck starship.toml` and fix the reported line","Run `starship print-config` - if it also fails, the TOML is broken and the error output identifies the offset","Temporarily move the file aside (`mv ~/.config/starship.toml ~/.config/starship.toml.bak`) to confirm it is the source, then restore pieces gradually","Regenerate a known-good base with `starship preset plain-text-symbols > ~/.config/starship.toml` (or toml) and re-apply your changes in small batches"],"exampleFix":"// before (src/configure.rs)\ntoml_content\n    .unwrap_or_default()\n    .parse::<DocumentMut>()\n    .expect(\"Failed to load starship config\")\n\n// after\nmatch toml_content.unwrap_or_default().parse::<DocumentMut>() {\n    Ok(doc) => doc,\n    Err(e) => {\n        eprintln!(\"Failed to parse starship config: {e}\");\n        process::exit(1);\n    }\n}","handlingStrategy":"validation","validationCode":"# before launching the editor / calling starship config\nif [ -f \"$STARSHIP_CONFIG\" ] || [ -f \"$HOME/.config/starship.toml\" ]; then\n  CFG=\"${STARSHIP_CONFIG:-$HOME/.config/starship.toml}\"\n  # fast TOML syntax check using python (available almost everywhere)\n  python3 - \"$CFG\" <<'EOF' || exit 1\nimport sys, tomllib\ntry:\n    tomllib.load(open(sys.argv[1], 'rb'))\nexcept Exception as e:\n    sys.exit(f'starship.toml is invalid: {e}')\nEOF\nfi","typeGuard":"// Rust callers: guard before get_configuration_edit\nfn config_is_valid_toml(path: &std::path::Path) -> bool {\n    std::fs::read_to_string(path)\n        .map(|s| s.parse::<toml_edit::DocumentMut>().is_ok())\n        .unwrap_or(true) // missing file behaves as empty (parses fine)\n}","tryCatchPattern":"// Embedding starship: isolate the panic at the boundary\nlet doc = std::panic::catch_unwind(|| {\n    starship::configure::get_configuration_edit(&context)\n});\nmatch doc {\n    Ok(d) => { /* edit d */ },\n    Err(_) => eprintln!(\"starship.toml has invalid TOML; fix syntax before editing\"),\n}","preventionTips":["Lint starship.toml in CI or editor with a TOML language server (even-tap/taplo) so syntax errors surface at edit time","After hand-edits, run `starship print-config` once to confirm the file still parses before restarting your shell","Keep configuration under a dotfiles repo so a broken edit is always one `git checkout` away from recovery"],"tags":["toml","config","panic","starship"],"backgroundTag":null,"analyzedSha":"c13a634f3925a046826c26bf992ec6cf9f48725c","analyzedAt":"2026-08-16T08:06:39.319Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}