{"record":{"id":"fac25c426c4c38fd","repo":"ReactiveX/rxjs","slug":"out-dir-is-required-with-write","errorCode":null,"errorMessage":"--out-dir is required with --write","messagePattern":"--out-dir is required with --write","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/migrate/src/cli.ts","lineNumber":173,"sourceCode":"        options.help = true;\n        break;\n      default:\n        if (argument.startsWith('-')) throw new Error(`Unknown option: ${argument}`);\n        options.files.push(argument);\n    }\n  }\n  return options;\n}\n\nfunction validateArguments(options: CliOptions): asserts options is RunnableCliOptions {\n  const missing = [\n    options.files.length === 0 ? 'at least one source file' : undefined,\n    options.sourceRoot ? undefined : '--source-root',\n    options.repository ? undefined : '--source-repo',\n    options.sha ? undefined : '--source-sha',\n  ].filter((value): value is string => value !== undefined);\n  if (missing.length > 0) throw new Error(`Missing required argument${missing.length === 1 ? '' : 's'}: ${missing.join(', ')}`);\n  if (options.write && !options.outputRoot) throw new Error('--out-dir is required with --write');\n}\n\nfunction requiredValue(argv: readonly string[], index: number, option: string): string {\n  const value = argv[index];\n  if (!value || value.startsWith('-')) throw new Error(`${option} requires a value`);\n  return value;\n}\n\nfunction errorReport(code: MigrationCliErrorReport['error']['code'], message: string): MigrationCliErrorReport {\n  return { schemaVersion: migrationCliReportSchemaVersion, status: 'error', error: { code, message } };\n}\n\nfunction writeJson(stream: Pick<NodeJS.WriteStream, 'write'>, value: MigrationCliReport | MigrationCliErrorReport): void {\n  stream.write(`${JSON.stringify(value, null, 2)}\\n`);\n}\n\nfunction messageFor(error: unknown): string {\n  return error instanceof Error ? error.message : String(error);","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/ReactiveX/rxjs/blob/54796b38a57e6309f9861e174737479bb3f63f61/packages/migrate/src/cli.ts#L155-L191","documentation":"Thrown by validateArguments when --write is set but --out-dir (which populates outputRoot) is not. The tool refuses to write in-place, so dry-run planning needs no output directory but an actual write requires an explicit destination.","triggerScenarios":"Running the CLI with --write but no --out-dir flag (or an --out-dir value that failed to parse).","commonSituations":"Assuming the tool overwrites source files in place like other codemods, or adding --write to an existing plan-only command without also adding the output directory.","solutions":["Add --out-dir <path> alongside --write","If you only want a plan/report, remove --write","Verify the --out-dir value is not empty or misparsed"],"exampleFix":"# before\nnpx @rxjs/migrate --write spec/app.spec.ts\n# after\nnpx @rxjs/migrate --write --out-dir migrated spec/app.spec.ts","handlingStrategy":"validation","validationCode":"if (write && !outputRoot) throw new Error('Pass --out-dir when using --write');","typeGuard":"const canWrite = (o: {write:boolean; outputRoot?:string}): boolean => !o.write || !!o.outputRoot;","tryCatchPattern":"try { runCli(argv); } catch (e) { console.error((e as Error).message); }","preventionTips":["Treat --write and --out-dir as a pair in scripts","Default out-dir in your wrapper when write is enabled"],"tags":["cli","argument-validation","filesystem"],"backgroundTag":"missing-required-parameter","analyzedSha":"54796b38a57e6309f9861e174737479bb3f63f61","analyzedAt":"2026-08-28T10:21:27.410Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}