{"record":{"id":"861fb92e0c57135e","repo":"denoland/deno","slug":"illegal-constructor","errorCode":null,"errorMessage":"Illegal constructor","messagePattern":"Illegal constructor","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/process/40_process.js","lineNumber":482,"sourceCode":"  get stderr() {\n    if (this.#stderr == null) {\n      throw new TypeError(\"Cannot get 'stderr': 'stderr' is not piped\");\n    }\n    return this.#stderr;\n  }\n\n  constructor(key = null, {\n    signal,\n    rid,\n    pid,\n    stdinRid,\n    stdoutRid,\n    stderrRid,\n    ipcPipeRid, // internal\n    extraPipeRids,\n  } = null) {\n    if (key !== illegalConstructorKey) {\n      throw new TypeError(\"Illegal constructor\");\n    }\n\n    this.#rid = rid;\n    this.#pid = pid;\n    this[_ipcPipeRid] = ipcPipeRid;\n    this[_extraPipeRids] = extraPipeRids;\n    this[_stdinRid] = stdinRid;\n    this[_stdoutRid] = stdoutRid;\n    this[_stderrRid] = stderrRid;\n\n    if (stdinRid !== null) {\n      this.#stdin = writableStreamForRid(stdinRid);\n    }\n\n    if (stdoutRid !== null) {\n      this.#stdout = readableStreamForRidUnrefable(\n        stdoutRid,\n        ReadableStreamWithCollectors,","sourceCodeStart":464,"sourceCodeEnd":500,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/process/40_process.js#L464-L500","documentation":"ChildProcess has no public constructor; its constructor requires a private illegalConstructorKey symbol only Deno's internal spawn machinery possesses. Trying to construct it directly throws a TypeError. This is Deno's standard pattern for classes whose instances must come from a factory (here, Deno.Command.prototype.spawn()).","triggerScenarios":"Executing new ChildProcess(...) in user code (ChildProcess is not even exported on the Deno namespace), or passing deserialized/forged constructor arguments to build one manually.","commonSituations":"Copying internal source into user code; attempting to subclass or mock ChildProcess with new; confusing the class with process.nextTick-style globals while writing test doubles.","solutions":["Get instances only via new Deno.Command(cmd, opts).spawn()","If you need a ChildProcess-like object in tests, create one from a real cheap command (e.g. Deno.execPath() with args: [\"eval\", \"\"]) instead of constructing the class","For type annotations, import the type from Deno's built-in typings (Deno.ChildProcess) rather than instantiating"],"exampleFix":"// before\nconst child = new ChildProcess({ rid: 3, pid: 42 }); // TypeError: Illegal constructor\n\n// after\nconst child = new Deno.Command(Deno.execPath(), { args: [\"eval\", \"\"], stdout: \"piped\" }).spawn();","handlingStrategy":"validation","validationCode":"const child = new Deno.Command(cmd, { stdout: \"piped\" }).spawn(); // the only sanctioned factory","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never construct framework classes with illegal-constructor guards; look for the factory method","Use the Deno.ChildProcess type only for annotations, never for instantiation","Build test doubles from real cheap commands (Deno.execPath() + eval) instead of forging instances"],"tags":["deno","illegal-constructor","child-process","spawn"],"backgroundTag":"illegal-constructor","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}