a-b-street/abstreet · error · anyhow::Error

writing binary files on web unsupported

Error message

writing binary files on web unsupported

What it means

FileSaver::new_state's wasm branch downloads files via abstio::write_file, which can only handle text; when the payload is FileSaverContents::Bytes it immediately returns anyhow!("writing binary files on web unsupported"). Binary saving on web would need encoding (e.g. base64) that isn't implemented.

Solutions

  1. Convert binary data to a text-safe format (base64) before saving on web, then decode on load
  2. Save only String contents on web, or gate binary-saving features to native builds
  3. Extend abstio::write_file to support Blobs/arraybuffers for binary downloads

Example fix

// before
FileSaverContents::Bytes(_bytes) => Err(anyhow!("writing binary files on web unsupported")),
// after
FileSaverContents::Bytes(bytes) => {
    let b64 = base64::encode(&bytes);
    abstio::write_file(filename, b64)
}
Defensive patterns

Strategy: validation

Validate before calling

// guard before saving binary data on web
if matches!(contents, FileSaverContents::Bytes(_)) && cfg!(target_arch = "wasm32") {
    // encode to base64 or block the feature
}

Try / catch

if let Err(e) = saver.consume() {
    if e.to_string().contains("binary files on web unsupported") {
        // fall back to text encoding or notify user
    }
}

Prevention

When it happens

Trigger: Attempting to save binary data (Bytes variant, e.g. a downloaded map binary or raw image) from the web build via the FileSaver UI.

Common situations: Running abstreet in a browser and triggering an export that stores Bytes instead of String; a feature added for native saving then exercised on web.

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/b911045d19ed4c6f. Report an issue: GitHub.

Appendix: source

Thrown at map_gui/src/tools/ui.rs:111

                } else {
                    Err(anyhow!("no file chosen to save"))
                };

                #[cfg(target_arch = "wasm32")]
                let result = {
                    // Hide an unused warning
                    let _ = builder;

                    // TODO No file save dialog on WASM until
                    // https://developer.mozilla.org/en-US/docs/Web/API/Window/showSaveFilePicker
                    match write {
                        FileSaverContents::String(string) => {
                            abstio::write_file(filename.clone(), string)
                        }
                        FileSaverContents::Bytes(_bytes) => {
                            // We need to use write_file (which downloads a file), but encode
                            // binary data the right way
                            Err(anyhow!("writing binary files on web unsupported"))
                        }
                    }
                };

                let wrap: Box<dyn Send + FnOnce(&A) -> Result<String>> =
                    Box::new(move |_: &A| result);
                Ok(wrap)
            }),
            outer_progress_rx,
            inner_progress_rx,
            "Waiting for a file to be chosen",
            on_load,
        )
    }

    // Popup a success or failure message after
    pub fn with_default_messages<A: 'static + AppLike>(
        ctx: &mut EventCtx,

View on GitHub (pinned to 0964f29315)