google/zx · error · Fail

Trying to kill a process without creating one.

Error message

Trying to kill a process without creating one.

What it means

Thrown by ProcessPromise.kill() when this.child is null — the child process has not been spawned yet. There is no pid to signal before run() spawns the process.

Source

Thrown at src/core.ts:449

      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'
  ): this {
    this._snapshot.stdio = Array.isArray(stdin)
      ? stdin
      : [stdin, stdout, stderr]
    return this
  }

  nothrow(v = true): this {

View on GitHub (pinned to 00a2c484e2)

Solutions

  1. Ensure the process started: for halted promises call `pp.run()` first.
  2. Kill from the 'start' callback or after a tick (`setImmediate`).
  3. Use $.timeout instead of manual kill for bounded execution.

Example fix

// before
const pp = $({ halt: true })`sleep 10`
pp.kill()
// after
const pp = $({ halt: true })`sleep 10`
pp.run()
pp.kill()
Defensive patterns

Strategy: validation

Validate before calling

function killIfRunning(pp: ProcessPromise): void {
  if (pp.stage === 'running') pp.kill()
  else if (pp.stage === 'halted') { pp.run(); pp.kill() }
}

Try / catch

try {
  pp.kill()
} catch (e) {
  if (e instanceof Fail && /without creating one/.test(e.message)) {
    pp.run(); pp.kill()
  } else throw e
}

Prevention

When it happens

Trigger: Calling kill() on a halted ProcessPromise before .run(); killing synchronously in the same tick as `$` creation before spawn; killing a command that was constructed but never run.

Common situations: Halted pipelines killed before launch; immediate kill after creation; deferred command graphs.

Related errors


AI-assisted analysis of google/zx@00a2c484e2 (2026-08-13). Data as JSON: /api/errors/1c8bab32f19237ea. Report an issue: GitHub.