google/zx · error · Fail
Trying to abort a process without creating one.
Error message
Trying to abort a process without creating one.
What it means
Thrown by ProcessPromise.abort() when this.child is null — i.e. the underlying child process has not been spawned yet. The AbortController has nothing to signal before the process starts running.
Source
Thrown at src/core.ts:441
this._stage = 'fulfilled'
this._resolve(output)
} else {
this._stage = 'rejected'
if (legacy) {
this._resolve(output) // to avoid unhandledRejection alerts
throw output.cause || output
}
this._reject(output)
if (this.sync) throw output
}
}
abort(reason?: string) {
if (this.isSettled()) throw new Fail('Too late to abort the process.')
if (this.signal !== this.ac.signal)
throw new Fail('The signal is controlled by another process.')
if (!this.child)
throw new Fail('Trying to abort a process without creating one.')
this.ac.abort(reason)
}
kill(signal?: NodeJS.Signals | null): Promise<void> {
if (this.isSettled()) throw new Fail('Too late to kill the process.')
if (!this.child)
throw new Fail('Trying to kill a process without creating one.')
if (!this.pid) throw new Fail('The process pid is undefined.')
return $.kill(this.pid, signal || this._snapshot.killSignal || $.killSignal)
}
// Configurators
stdio(
stdin: IOType | StdioOptions,
stdout: IOType = 'pipe',
stderr: IOType = 'pipe'View on GitHub (pinned to 00a2c484e2)
Solutions
- Ensure the process has started: for halted promises call `pp.run()` first.
- Defer the abort a tick: `setImmediate(() => pp.abort())`.
- Abort from the 'start' event or use $.timeout for bounded behavior.
Example fix
// before
const pp = $({ halt: true })`sleep 10`
pp.abort()
// after
const pp = $({ halt: true })`sleep 10`
pp.run()
pp.abort() Defensive patterns
Strategy: validation
Validate before calling
// child is private; ensure the process is running before aborting
function abortIfRunning(pp: ProcessPromise): void {
if (pp.stage === 'running') pp.abort()
else setImmediate(() => pp.stage === 'running' && pp.abort())
} Try / catch
try {
pp.abort()
} catch (e) {
if (e instanceof Fail && /without creating one/.test(e.message)) {
pp.run() // for halted promises
pp.abort()
} else throw e
} Prevention
- For halted pipelines, call pp.run() before abort/kill.
- Defer abort with setImmediate to let the spawn microtask complete.
- Abort from the 'start' event to guarantee a child exists.
When it happens
Trigger: Calling abort() on a halted ProcessPromise (`$({halt:true})`) before .run() is invoked; aborting synchronously in the same tick as `$` creation before the spawn microtask runs; aborting a command that was never run.
Common situations: Halted pipelines where run() is deferred; abort wired to synchronous setup code; deferred command graphs that abort before launch.
Related errors
- Trying to kill a process without creating one.
- Too late to abort the process.
- The signal is controlled by another process.
- Too late to kill the process.
- Cannot pipe to a settled process.
AI-assisted analysis of google/zx@00a2c484e2 (2026-08-13).
Data as JSON: /api/errors/b5be4476bf7007f8.
Report an issue: GitHub.