denoland/deno · error
Invalid arguments
Error message
Invalid arguments
What it means
spawn() validates SpawnOptions before touching CreateProcessW: the executable path (options.file) and the argv vector (options.args) must both be non-empty, because the Windows command line is assembled from at least the program name. An empty program string or empty argv is rejected immediately with ErrorKind::InvalidInput 'Invalid arguments'.
Source
Thrown at runtime/subprocess_windows/src/process.rs:530
let err = io::Error::last_os_error();
drop(unsafe { Box::from_raw(ptr) });
return Poll::Ready(Err(err));
}
inner.waiting = Some(Waiting {
rx,
wait_object,
tx: ptr,
});
}
}
}
pub fn spawn(options: &SpawnOptions) -> Result<ChildProcess, std::io::Error> {
let mut startup = unsafe { mem::zeroed::<STARTUPINFOW>() };
let mut info = unsafe { mem::zeroed::<PROCESS_INFORMATION>() };
if options.file.is_empty() || options.args.is_empty() {
return Err(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"Invalid arguments",
));
}
// Convert file path to UTF-16
let application = WCString::new(&options.file);
// Create environment block if provided
let env_saw_path = options.env.have_changed_path();
let maybe_env = options.env.capture_if_changed();
let child_paths = if env_saw_path {
if let Some(env) = maybe_env.as_ref() {
env.get(&EnvKey::new("PATH")).map(|s| s.as_os_str())
} else {
None
}View on GitHub (pinned to 9ad36f7a2c)
Solutions
- Validate the command string is non-empty before constructing Deno.Command
- Fix the source of the empty string: required env var, config field, or CLI argument
- Fail fast with a clear app-level error or provide a sensible default program
Example fix
// before
const cmd = new Deno.Command(Deno.env.get("PAGER") ?? "");
// after
const pager = Deno.env.get("PAGER");
if (!pager) throw new Error("PAGER environment variable is required");
const cmd = new Deno.Command(pager); Defensive patterns
Strategy: validation
Validate before calling
if (typeof prog !== "string" || prog.length === 0) {
throw new Error("command must be a non-empty string");
}
const cmd = new Deno.Command(prog); Type guard
const isNonEmptyString = (v: unknown): v is string => typeof v === "string" && v.length > 0;
Prevention
- Resolve commands from env/config with a required-check helper, not `?? ""
- Fail fast with a clear app-level message when a command name is missing
- Unit-test command construction with empty and missing inputs
When it happens
Trigger: new Deno.Command("") on Windows (empty command string), or any API path such as Node-compat child_process or internal tooling that reaches spawn with an empty argv vector.
Common situations: Command name read from an unset env var or missing config field (resolving to an empty string); template strings that trim to empty; CLI wrappers forwarding an optional command that was never provided.
Related errors
- ERR_FS_INVALID_SYMLINK_TYPE
- {}: ({}) {}
- failed to unregister: {}
- nul byte found in provided data
- Process not found
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/9fc432478a24c0b8.
Report an issue: GitHub.