a-b-street/abstreet · error

Don't know MIME type for

Error message

Don't know MIME type for {path}

What it means

abstio::write_file on web triggers a browser download by constructing a data: URL, which requires a known MIME type. If the filename's extension is not one of the recognized ones (csv, json, bin, etc.), it bails with "Don't know MIME type for {path}".

Solutions

  1. Rename the output to one of the supported extensions (.csv, .json/.geojson, .bin).
  2. Add a mapping for the needed extension in write_file's MIME table.
  3. Serialize the content into a supported format (e.g. write JSON instead of XML/YAML).

Example fix

// before
abstio::write_file("summary.txt", contents);
// after
abstio::write_file("summary.json", contents);
Defensive patterns

Strategy: validation

Validate before calling

fn has_supported_download_ext(path: &str) -> bool {
    ["csv", "json", "bin"].iter().any(|ext| path.ends_with(ext))
}

Try / catch

if !has_supported_download_ext(&filename) {
    filename.push_str(".json"); // coerce to a supported type before exporting
}
abstio::write_file(&filename, contents);

Prevention

When it happens

Trigger: Calling write_file with an extension outside the supported list — e.g. .txt, .xml, .geojson variants not ending exactly in "json" (note the check is ends_with("json"), which does cover .geojson), .yaml, or no extension at all.

Common situations: Exporting custom formats from an app running in the browser; renaming output files to a new extension; typos in the extension.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of a-b-street/abstreet@0964f29315 (2026-09-13). Data as JSON: /api/errors/109d35ab94971307. Report an issue: GitHub.

Appendix: source

Thrown at abstio/src/io_web.rs:204

    for idx in 0..storage.length().unwrap() {
        keys.push(storage.key(idx).unwrap().unwrap());
    }
    keys
}

/// Returns path on success
pub fn write_file(path: String, contents: String) -> Result<String> {
    // Make the browser prompt the user to save a local file with arbitrary contents.
    use wasm_bindgen::JsCast;

    let mimetype = if path.ends_with("csv") {
        "text/csv"
    } else if path.ends_with("json") {
        "application/json"
    } else if path.ends_with("bin") {
        "application/octet-stream"
    } else {
        bail!("Don't know MIME type for {path}");
    };

    let data: String = js_sys::JsString::from(format!("data:{mimetype};charset=utf-8,"))
        .concat(&js_sys::encode_uri_component(&contents))
        .into();

    // TODO Proper error handling
    let window = web_sys::window().unwrap();
    let document = window.document().unwrap();
    let node = document
        .create_element("a")
        .unwrap()
        .dyn_into::<web_sys::HtmlElement>()
        .unwrap();
    node.set_attribute("href", &data).unwrap();
    node.set_attribute("download", &path).unwrap();
    document.body().unwrap().append_child(&node).unwrap();
    node.click();

View on GitHub (pinned to 0964f29315)