Morganamilo/paru · error · anyhow::Error
key can not contain null bytes
Error message
key can not contain null bytes
What it means
parse_env rejects environment variable keys containing NUL ('\0') bytes. NUL bytes are invalid in environment variable names on Unix (execve-style env blocks are NUL-delimited), so any key containing one would be truncated or rejected by the OS. The library raises this to fail early with a clear message.
Solutions
- Locate the offending [env] entry (e.g. grep -P '\x00' paru.conf) and remove the null byte
- Recreate the config file from a clean copy instead of editing the binary-corrupted file
- Validate the config is UTF-8 text: file/iconv check
Defensive patterns
Strategy: validation
Validate before calling
fn valid_env_key(key: &str) -> bool {
!key.is_empty() && !key.contains('\0')
} Prevention
- Keep config files as clean UTF-8 text
- Never write config files with binary tools
- Check for NUL bytes with grep -P '\x00' after programmatic edits
When it happens
Trigger: A key string parsed from the config [env] section contains a '\0' character, e.g. from a binary-corrupted config file or bad escaping.
Common situations: Corrupted or machine-generated paru.conf with embedded null bytes; files edited through tools that inserted NULs.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- value can not contain null bytes
- invalid value ' ' for key ' ', expected
- unknown mode
- section can not be called
- no local repo named
AI-assisted analysis of Morganamilo/paru@9ac3578807 (2026-09-12).
Data as JSON: /api/errors/3aa69eb04ae1b945.
Report an issue: GitHub.
Appendix: source
Thrown at src/config.rs:991
let repo = self.pkgbuild_repos.repo_mut(repo).unwrap();
match key {
"Url" => repo.source.set_url(Url::parse(value?)?),
"Path" => repo.source.set_path(value?.to_string()),
"Depth" => repo.depth = value?.parse()?,
"SkipReview" => repo.skip_review = true,
"GenerateSrcinfo" => repo.force_srcinfo = true,
_ => eprintln!("{}", tr!("error: unknown option '{}' in repo", key)),
}
Ok(())
}
fn parse_env(&mut self, key: &str, value: Option<&str>) -> Result<()> {
let value = value.context(tr!("key can not be empty"))?;
ensure!(!key.is_empty(), tr!("key can not be empty"));
ensure!(!key.contains('\0'), tr!("key can not contain null bytes"));
ensure!(
!value.contains('\0'),
tr!("value can not contain null bytes")
);
self.env.push((key.to_owned(), value.to_string()));
set_var(key, value);
Ok(())
}
fn parse_bin(&mut self, key: &str, value: Option<&str>) -> Result<()> {
let value = value
.map(|s| s.to_string())
.ok_or_else(|| anyhow!(tr!("key can not be empty")))?;
let split = value.split_whitespace().map(|s| s.to_string());
match key {View on GitHub (pinned to 9ac3578807)