astrid-runtime/astrid · error
Cargo rustflags array contains a non-string value in {}
Error message
Cargo rustflags array contains a non-string value in {} What it means
Array element validation in parse_rustflags: the rustflags value is an array, but one of its elements is not a string (e.g. an integer or nested array). Each array element must be an individual compiler flag string; a non-string element makes the flag list uninterpretable and absorb_document aborts naming the config file.
Source
Thrown at crates/astrid-build/src/rust/config.rs:406
Ok(content) => Ok(Some(content)),
Err(error) if error.kind() == std::io::ErrorKind::NotFound => Ok(None),
Err(error) => Err(error)
.with_context(|| format!("Failed to read Cargo configuration {}", path.display())),
}
}
struct ParsedRustflags {
flags: Vec<String>,
is_array: bool,
}
fn parse_rustflags(item: &toml_edit::Item, path: &Path) -> Result<ParsedRustflags> {
if let Some(array) = item.as_array() {
let flags = array
.iter()
.map(|value| {
value.as_str().map(str::to_owned).ok_or_else(|| {
anyhow::anyhow!(
"Cargo rustflags array contains a non-string value in {}",
path.display()
)
})
})
.collect::<Result<Vec<_>>>()?;
return Ok(ParsedRustflags {
flags,
is_array: true,
});
}
if let Some(value) = item.as_str() {
return Ok(ParsedRustflags {
flags: value.split_whitespace().map(str::to_owned).collect(),
is_array: false,
});
}
bail!(View on GitHub (pinned to affd8760f4)
Solutions
- Quote every element of the rustflags array
- Remove or stringify non-string elements
- Alternatively use the string form `rustflags = "flag1 flag2"` if supported
Example fix
# before [build] rustflags = ["-C", "target-cpu", 4] # after [build] rustflags = ["-C", "target-cpu=native"]
Defensive patterns
Strategy: validation
Validate before calling
fn validate_rustflags(item: &toml_edit::Item) -> Result<(), String> {
if let Some(arr) = item.as_array() {
for v in arr.iter() {
if v.as_str().is_none() {
return Err("all rustflags array elements must be strings".into());
}
}
}
Ok(())
} Type guard
fn rustflags_all_strings(item: &toml_edit::Item) -> bool {
item.as_array().map_or(true, |a| {
a.iter().all(|v| v.as_str().is_some())
})
} Try / catch
match absorb_document(...) {
Err(e) if e.to_string().contains("rustflags array contains a non-string") => {
eprintln!("quote every element in the rustflags array");
}
other => other?,
} Prevention
- Quote every rustflags array element, including flag values
- Prefer the string form rustflags = "-C ..." when mixing sources
- Lint .cargo/config.toml arrays for mixed types
When it happens
Trigger: absorb_document parsing `[build]\nrustflags = ["-C", "target-feature=+atomics", 42]` — any non-string array element triggers the error.
Common situations: Unquoted numeric-looking flags (e.g. -C link-arg=-O2 values left bare), copy-paste from JSON where numbers weren't quoted, mixing flags arrays with scalar forms.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Cargo include optional must be a boolean in {}
- existing [security.capsule_local_egress].{capsule_id} is not
- Cargo include table must contain a string path in {}
- capsule archive entry '{requested}' is not a regular file
- No Cargo build target selected. Set `[build] target = "wasm3
AI-assisted analysis of astrid-runtime/astrid@affd8760f4 (2026-09-09).
Data as JSON: /api/errors/64c1849a6ea29bb5.
Report an issue: GitHub.