linera-io/linera-protocol · error
could not parse OS string into string: {}
Error message
could not parse OS string into string: {} What it means
A filesystem path that must be returned as a String contains bytes that are not valid UTF-8. On Unix, paths are arbitrary byte strings; OsString::into_string() enforces UTF-8, so a temp dir or parent directory with non-UTF-8 bytes (odd locale filenames, corrupted names) makes the test-net config writer fail.
Source
Thrown at linera-service/src/cli_wrappers/local_net.rs:698
let host = exporter.host.clone();
let port = exporter.port;
let config_content = format!(
r#"
[[block_exporters]]
host = "{host}"
port = {port}
"#
);
content.push_str(&config_content);
}
}
}
fs_err::write(&path, content)?;
path.into_os_string().into_string().map_err(|error| {
anyhow!(
"could not parse OS string into string: {}",
error.to_string_lossy()
)
})
}
fn generate_block_exporter_config(
&self,
validator: usize,
exporter_id: u32,
destination_config: &DestinationConfig,
) -> String {
let n = validator;
let host = Network::Grpc.localhost();
let port = self.block_exporter_port(n, exporter_id as usize);
let metrics_port = Self::block_exporter_metrics_port(exporter_id as usize);
let mut config = format!(
r#"View on GitHub (pinned to 6c226ddcb3)
Solutions
- Set TMPDIR (and CARGO_TARGET_TMPDIR for Rust test tempdirs) to a clean UTF-8 path.
- Run the test suite from a checkout whose full path is valid UTF-8.
- Rename the offending directory.
- In library code, avoid the conversion: return/keep PathBuf, or use to_str() with an actionable error.
Example fix
// before: hard failure on non-UTF-8 path bytes
path.into_os_string().into_string().map_err(|error| {
anyhow!("could not parse OS string into string: {}", error.to_string_lossy())
})?
// after: keep the PathBuf — no UTF-8 requirement is actually needed
Ok(path) // callers use it as a path, not as a String Defensive patterns
Strategy: validation
Validate before calling
if path.to_str().is_none() {
anyhow::bail!(
"path {:#?} is not valid UTF-8 — set TMPDIR to a UTF-8 directory",
path.display()
);
} Type guard
fn is_utf8_path(p: &std::path::Path) -> bool {
p.to_str().is_some()
} Prevention
- Set TMPDIR/CARGO_TARGET_TMPDIR to clean UTF-8 paths in CI and dev shells.
- Prefer returning PathBuf over String for file paths in library APIs.
- Check checkout paths after extracting archives from other platforms.
When it happens
Trigger: local_net's configuration_string writes the validator config to a path derived from the temp/config directory, then converts it via into_string(); TMPDIR, CARGO_TARGET_TMPDIR, or the repo path containing non-UTF-8 bytes triggers the error.
Common situations: CI images or mount points with legacy-encoding directory names; a TMPDIR set from a misconfigured shell; filenames mangled during archive extraction across systems.
Related errors
- Expected an `ExecutionError`. Got: {self:#?}
- Expected an `ExecutionError`. Got: {chain_error:#?}
- Failed to obtain a port
- Notification subscription failed: {errors:?}
- Query result subscription failed: {errors:?}
AI-assisted analysis of linera-io/linera-protocol@6c226ddcb3 (2026-08-22).
Data as JSON: /api/errors/9932b61f8f914ff6.
Report an issue: GitHub.