cross-rs/cross · error
got of " " which is not a valid environment variable name…
Error message
got {var_type} of "{var}" which is not a valid environment variable name. the proper syntax is {var_syntax} What it means
Generic validation guard in validate_env_var: a `-e VAR=value` / `--env` / `--set-env` style argument passed to the container engine was split on '=' and the name part (or the whole argument, when no '=' was present) contains characters outside [A-Za-z0-9_], so it cannot be a valid environment variable name. Fires at most once per invocation thanks to the `warned` flag, and is only emitted when no '=' was found, since names are still reported for key=value forms.
Solutions
- Fix the argument to use only letters, digits and underscores in the variable name, e.g. `-e MY_VAR=value`
- Include an `=` with a value if you meant to set a variable rather than pass one through from the host
- Check for shell quoting problems that inject stray characters (spaces, dashes, newlines) into the env argument
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/docker/shared.rs:896 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of cross-rs/cross@8c1a8aa4b6 (2026-09-13).
Data as JSON: /api/errors/c2eb781985347091.
Report an issue: GitHub.
Appendix: source
Thrown at src/docker/shared.rs:896
fn validate_env_var<'a>(
var: &'a str,
warned: &mut bool,
var_type: &'static str,
var_syntax: &'static str,
msg_info: &mut MessageInfo,
) -> Result<(&'a str, Option<&'a str>)> {
let (key, value) = match var.split_once('=') {
Some((key, value)) => (key, Some(value)),
_ => (var, None),
};
if value.is_none()
&& !*warned
&& !var
.chars()
.all(|c| matches!(c, 'a'..='z' | 'A'..='Z' | '_' | '0'..='9'))
{
msg_info.warn(format_args!(
"got {var_type} of \"{var}\" which is not a valid environment variable name. the proper syntax is {var_syntax}"
))?;
*warned = true;
}
if key == "CROSS_RUNNER" {
eyre::bail!(
"CROSS_RUNNER environment variable name is reserved and cannot be pass through"
);
}
Ok((key, value))
}
impl CommandVariant {
pub(crate) fn safe_command(&self) -> SafeCommand {
SafeCommand::new(self.to_str())
}View on GitHub (pinned to 8c1a8aa4b6)