starship/starship · error
Failed to load starship config
Error message
Failed to load starship config
What it means
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'.
Source
Thrown at src/configure.rs:238
values.insert(key, new_value);
Ok(())
}
pub fn get_configuration(context: &Context) -> toml::Table {
let starship_config = StarshipConfig::initialize(context.get_config_path_os().as_deref());
starship_config.config.unwrap_or_default()
}
pub fn get_configuration_edit(context: &Context) -> DocumentMut {
let config_file_path = context.get_config_path_os();
let toml_content = StarshipConfig::read_config_content_as_str(config_file_path.as_deref());
toml_content
.unwrap_or_default()
.parse::<DocumentMut>()
.expect("Failed to load starship config")
}
pub fn write_configuration(context: &Context, doc: &DocumentMut) {
let Some(config_path) = context.get_config_path_os() else {
eprintln!("config path required to write configuration");
process::exit(1);
};
let config_path = PathBuf::from(config_path);
if let Err(e) = crate::utils::write_file_atomic(config_path, doc.to_string(), true) {
eprintln!("Unable to write configuration: {e}");
process::exit(1);
}
}
pub fn edit_configuration(
context: &Context,View on GitHub (pinned to c13a634f39)
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
Example fix
// before (src/configure.rs)
toml_content
.unwrap_or_default()
.parse::<DocumentMut>()
.expect("Failed to load starship config")
// after
match toml_content.unwrap_or_default().parse::<DocumentMut>() {
Ok(doc) => doc,
Err(e) => {
eprintln!("Failed to parse starship config: {e}");
process::exit(1);
}
} Defensive patterns
Strategy: validation
Validate before calling
# before launching the editor / calling starship config
if [ -f "$STARSHIP_CONFIG" ] || [ -f "$HOME/.config/starship.toml" ]; then
CFG="${STARSHIP_CONFIG:-$HOME/.config/starship.toml}"
# fast TOML syntax check using python (available almost everywhere)
python3 - "$CFG" <<'EOF' || exit 1
import sys, tomllib
try:
tomllib.load(open(sys.argv[1], 'rb'))
except Exception as e:
sys.exit(f'starship.toml is invalid: {e}')
EOF
fi Type guard
// Rust callers: guard before get_configuration_edit
fn config_is_valid_toml(path: &std::path::Path) -> bool {
std::fs::read_to_string(path)
.map(|s| s.parse::<toml_edit::DocumentMut>().is_ok())
.unwrap_or(true) // missing file behaves as empty (parses fine)
} Try / catch
// Embedding starship: isolate the panic at the boundary
let doc = std::panic::catch_unwind(|| {
starship::configure::get_configuration_edit(&context)
});
match doc {
Ok(d) => { /* edit d */ },
Err(_) => eprintln!("starship.toml has invalid TOML; fix syntax before editing"),
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Unexpected error returned in root format variables
- can't init_main
- can't init_stub
- Failed to initialize worker thread pool
- Unable to determine HOME_DIR for user
AI-assisted analysis of starship/starship@c13a634f39 (2026-08-16).
Data as JSON: /api/errors/3d7c725c4e53214b.
Report an issue: GitHub.