Hmbown/CodeWhale · error · io::Error (InvalidInput)
xz compression level
Error message
xz compression level {} is out of range 0-9 What it means
write_session_archive only accepts xz compression levels 0 through 9. Passing `SessionArchiveOptions.compression_level` greater than 9 is rejected up front with InvalidInput, since the underlying xz encoder does not support it. The error message includes the offending level value.
Solutions
- Clamp the level to 0..=9 before calling: `options.compression_level = options.compression_level.min(9)`.
- Fix the CLI/config parsing to enforce the 0-9 range (e.g. `value_range(0..=9)` or a `clap` value parser).
- Use level 9 for maximum compression, or 6 as the typical xz default.
- Check the source of the value — if it comes from another tool's preset, map it into xz's range.
Example fix
// before
let options = SessionArchiveOptions { compression_level: 12, ..opts };
write_session_archive(&session, dir, out, options)?;
// after
let options = SessionArchiveOptions { compression_level: opts.compression_level.clamp(0, 9), ..opts };
write_session_archive(&session, dir, out, options)?; Defensive patterns
Strategy: validation
Validate before calling
fn valid_compression_level(level: i32) -> bool { (0..=9).contains(&level) }
// call before: assert!(valid_compression_level(options.compression_level)); Type guard
fn in_xz_range(level: i32) -> Option<u32> { u32::try_from(level).ok().filter(|l| *l <= 9) } Try / catch
match write_session_archive(&session, dir, out, opts) {
Err(e) if e.to_string().contains("out of range 0-9") => {
let mut opts = opts; opts.compression_level = 6;
write_session_archive(&session, dir, out, opts)?;
}
other => other?,
} Prevention
- Parse the level with a 0..=9 value parser at the CLI boundary
- Don't reuse level presets from gzip/zstd; map them into xz's range
- Default to level 6 (xz default) unless the user opts into more
When it happens
Trigger: Calling `write_session_archive` with `options.compression_level = 10` or higher (or a value computed/parsed from user input without clamping).
Common situations: A CLI flag parsed with the wrong type or bounds; a config file where the level was set for a different library (e.g. gzip-style 0-12 or zstd levels); arithmetic producing an off-by-one level.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- A positive pull request number is required
- already exists; pass --force to overwrite it
- API key contains invalid control characters
- API key id must be lowercase hex characters — the part…
- API key input is unexpectedly large
AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15).
Data as JSON: /api/errors/2967314db6050645.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tui/src/session_export.rs:153
/// only.
///
/// The archive is streamed to a sibling temporary file and renamed into
/// place, so a failed export never leaves a truncated archive at `output`.
/// An existing `output` is replaced only when `options.overwrite` is set.
pub fn write_session_archive(
session: &SavedSession,
sessions_dir: Option<&Path>,
output: &Path,
options: SessionArchiveOptions,
) -> io::Result<SessionArchiveSummary> {
if !is_valid_session_id(&session.metadata.id) {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
"invalid session id",
));
}
if options.compression_level > 9 {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
format!(
"xz compression level {} is out of range 0-9",
options.compression_level
),
));
}
let session_json = session_json(session)?;
let container_json = container_json(session)?;
let parent = output
.parent()
.filter(|parent| !parent.as_os_str().is_empty())
.map_or_else(|| PathBuf::from("."), Path::to_path_buf);
fs::create_dir_all(&parent)?;
let sessions_dir = sessions_dir.map(Path::canonicalize).transpose()?;
if let Some(root) = &sessions_dir
&& parent.canonicalize()?.starts_with(root)
{View on GitHub (pinned to 433685b202)