fish-shell/fish-shell · error

Content of {path} is not valid UTF-8: {e}

Error message

Content of {path} is not valid UTF-8: {e}

What it means

After successfully fetching the embedded FTL file, read_ftl_file() converts its bytes to a String with String::from_utf8 and panics if the embedded translation resource for {path} contains bytes that are not valid UTF-8 — the packaged asset is corrupted or mis-encoded.

Source

Thrown at crates/fluent/src/lib.rs:75

            Cow::Owned(mut language) => {
                assert!(language.ends_with(suffix));
                language.truncate(language.len() - suffix.len());
                Box::leak(Box::new(language))
            }
        });
        FluentLocalizationLanguage(language)
    }))
});

pub fn get_available_languages() -> &'static HashSet<FluentLocalizationLanguage> {
    &AVAILABLE_LANGUAGES
}

fn read_ftl_file(path: &str) -> String {
    let file = FtlFiles::get(path)
        .unwrap_or_else(|| panic!("Tried to get FTL file {path} which does not exist."));
    String::from_utf8(Vec::from(file.data))
        .unwrap_or_else(|e| panic!("Content of {path} is not valid UTF-8: {e}"))
}

fn make_bundle(language: Language<'static>) -> Bundle {
    let langid: LanguageIdentifier = language
        .parse()
        .map_err(|e| format!("Failed to parse language identifier {language}: {e}"))
        .unwrap();
    let mut bundle = FluentBundle::new_concurrent(vec![langid]);
    let file_data = read_ftl_file(&format!("{language}.ftl"));
    // Error handling could use fluent_ftl_tools::display_parse_errors(), but that would require
    // making the crate a regular dependency.
    match FluentResource::try_new(file_data) {
        Ok(res) => {
            bundle
                .add_resource(res)
                .map_err(|e| {
                    format!(
                        "Failed to add FTL resources to the bundle for language {language}: {e:?}"

View on GitHub (pinned to edb719d76c)

Solutions

  1. Re-save the offending .ftl file as UTF-8 (no BOM issues) and rebuild
  2. Use String::from_utf8_lossy to tolerate invalid bytes instead of panicking
  3. Add a build/lint step validating that all embedded FTL assets are valid UTF-8
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/fluent/src/lib.rs:75 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of fish-shell/fish-shell@edb719d76c (2026-09-03). Data as JSON: /api/errors/34d19cb7fdf921b6. Report an issue: GitHub.