{"record":{"id":"7a5db7210a4c82ff","repo":"a-b-street/abstreet","slug":"can-t-write-binary","errorCode":null,"errorMessage":"Can't write_binary({}): {}","messagePattern":"Can't write_binary\\((.+?)\\): (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"abstio/src/io_native.rs","lineNumber":93,"sourceCode":"    }\n    info!(\"Wrote {}\", path);\n}\n\nfn maybe_write_binary<T: Serialize>(path: &str, obj: &T) -> Result<()> {\n    if !path.ends_with(\".bin\") {\n        panic!(\"write_binary needs {} to end with .bin\", path);\n    }\n\n    fs_err::create_dir_all(std::path::Path::new(path).parent().unwrap())\n        .expect(\"Creating parent dir failed\");\n\n    let file = BufWriter::new(File::create(path)?);\n    bincode::serialize_into(file, obj).map_err(|err| err.into())\n}\n\npub fn write_binary<T: Serialize>(path: String, obj: &T) {\n    if let Err(err) = maybe_write_binary(&path, obj) {\n        panic!(\"Can't write_binary({}): {}\", path, err);\n    }\n    info!(\"Wrote {}\", path);\n}\n\npub fn write_raw(path: String, bytes: &[u8]) -> Result<()> {\n    fs_err::create_dir_all(std::path::Path::new(&path).parent().unwrap())?;\n\n    let mut file = BufWriter::new(File::create(path)?);\n    file.write_all(bytes)?;\n    Ok(())\n}\n\n/// Idempotent\npub fn delete_file<I: AsRef<str>>(path: I) {\n    let path = path.as_ref();\n    if fs_err::remove_file(path).is_ok() {\n        info!(\"Deleted {}\", path);\n    } else {","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/a-b-street/abstreet/blob/0964f29315820c91b171b585eb51e300164e9197/abstio/src/io_native.rs#L75-L111","documentation":"write_binary bincode-serializes obj to a BufWriter over a newly created file at path, panicking with this message on failure. The path must end with .bin (otherwise maybe_write_binary panics differently), and parent directories are auto-created first. This panic fires when the file can't be created or bincode serialization into the writer fails.","triggerScenarios":"Calling write_binary(path, obj) where File::create fails (read-only filesystem, permission denied, invalid path, ENOSPC) or bincode::serialize_into errors (I/O failure mid-write, or serialization limits exceeded for very large objects).","commonSituations":"Disk-full or quota errors while dumping large datasets; read-only output mounts in CI/containers; output directories lacking write permission; bincode size-limit exceeded when serializing a huge structure with the default config.","solutions":["Check available disk space and quotas, and confirm the output filesystem is writable.","Verify the path ends with .bin and its parent is a writable directory (write_binary creates it, but permission is still needed).","If serializing a very large object, raise the bincode size limit (bincode::config with no_limit) or write via a Result-returning path.","Fix directory permissions (chmod/chown) or choose a different output location."],"exampleFix":"// before\nabstio::write_binary(\"/mnt/ro/out/data.bin\".to_string(), &dataset);\n\n// after\nlet path = \"/mnt/ro/out/data.bin\";\nmatch free_disk_bytes(\"/mnt/ro/out\") {\n    Some(free) if free > dataset.len() * 8 => abstio::write_binary(path.to_string(), &dataset),\n    _ => eprintln!(\"skipping write: {} not writable or not enough space\", path),\n}","handlingStrategy":"validation","validationCode":"if !path.ends_with(\".bin\") {\n    eprintln!(\"write_binary requires .bin extension: {}\", path);\n}\nlet parent = std::path::Path::new(&path).parent();\nif parent.map_or(true, |d| !d.is_dir()) {\n    eprintln!(\"parent dir for {} missing\", path);\n}\nlet free = fs2::available_space(parent.unwrap());\nif free < estimated_size {\n    eprintln!(\"only {} bytes free\", free);\n}","typeGuard":"fn is_writable_bin_path(path: &str) -> bool {\n    let p = std::path::Path::new(path);\n    path.ends_with(\".bin\")\n        && p.parent().map_or(false, |d| d.is_dir())\n        && std::fs::OpenOptions::new().write(true).create(true).open(p).is_ok()\n}","tryCatchPattern":"// write_binary panics; probe writability first:\nmatch std::fs::File::create(&path) {\n    Ok(_) => abstio::write_binary(path.clone(), &obj),\n    Err(e) => eprintln!(\"can't write {}: {}\", path, e),\n}","preventionTips":["Always end output paths with .bin when using write_binary.","Check free disk space before serializing very large structures.","Watch for bincode size-limit errors on huge objects; configure a larger limit if needed.","Verify write permissions on the output volume, especially in read-only container mounts."],"tags":["rust","panic","serialization","bincode","file-io"],"backgroundTag":"file-write-failed","analyzedSha":"0964f29315820c91b171b585eb51e300164e9197","analyzedAt":"2026-09-13T18:02:03.421Z","contentChangedAt":"2026-09-13T18:02:03.421Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}