{"record":{"id":"1c8bab32f19237ea","repo":"google/zx","slug":"trying-to-kill-a-process-without-creating-one","errorCode":null,"errorMessage":"Trying to kill a process without creating one.","messagePattern":"Trying to kill a process without creating one\\.","errorType":"exception","errorClass":"Fail","httpStatus":null,"severity":"error","filePath":"src/core.ts","lineNumber":449,"sourceCode":"      this._reject(output)\n      if (this.sync) throw output\n    }\n  }\n\n  abort(reason?: string) {\n    if (this.isSettled()) throw new Fail('Too late to abort the process.')\n    if (this.signal !== this.ac.signal)\n      throw new Fail('The signal is controlled by another process.')\n    if (!this.child)\n      throw new Fail('Trying to abort a process without creating one.')\n\n    this.ac.abort(reason)\n  }\n\n  kill(signal?: NodeJS.Signals | null): Promise<void> {\n    if (this.isSettled()) throw new Fail('Too late to kill the process.')\n    if (!this.child)\n      throw new Fail('Trying to kill a process without creating one.')\n    if (!this.pid) throw new Fail('The process pid is undefined.')\n\n    return $.kill(this.pid, signal || this._snapshot.killSignal || $.killSignal)\n  }\n\n  // Configurators\n  stdio(\n    stdin: IOType | StdioOptions,\n    stdout: IOType = 'pipe',\n    stderr: IOType = 'pipe'\n  ): this {\n    this._snapshot.stdio = Array.isArray(stdin)\n      ? stdin\n      : [stdin, stdout, stderr]\n    return this\n  }\n\n  nothrow(v = true): this {","sourceCodeStart":431,"sourceCodeEnd":467,"githubUrl":"https://github.com/google/zx/blob/00a2c484e219c2e84bfc3a199febf7fbce2cfbf4/src/core.ts#L431-L467","documentation":"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.","triggerScenarios":"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.","commonSituations":"Halted pipelines killed before launch; immediate kill after creation; deferred command graphs.","solutions":["Ensure the process started: for halted promises call `pp.run()` first.","Kill from the 'start' callback or after a tick (`setImmediate`).","Use $.timeout instead of manual kill for bounded execution."],"exampleFix":"// before\nconst pp = $({ halt: true })`sleep 10`\npp.kill()\n// after\nconst pp = $({ halt: true })`sleep 10`\npp.run()\npp.kill()","handlingStrategy":"validation","validationCode":"function killIfRunning(pp: ProcessPromise): void {\n  if (pp.stage === 'running') pp.kill()\n  else if (pp.stage === 'halted') { pp.run(); pp.kill() }\n}","typeGuard":null,"tryCatchPattern":"try {\n  pp.kill()\n} catch (e) {\n  if (e instanceof Fail && /without creating one/.test(e.message)) {\n    pp.run(); pp.kill()\n  } else throw e\n}","preventionTips":["Ensure halted pipelines are run() before kill().","Kill from the 'start' callback or after setImmediate to guarantee a child exists.","Prefer $.timeout over eager manual kill."],"tags":["kill","lifecycle","halted","child-process"],"backgroundTag":null,"analyzedSha":"00a2c484e219c2e84bfc3a199febf7fbce2cfbf4","analyzedAt":"2026-08-13T02:11:06.305Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}