{"record":{"id":"4fd96d1e82c4685d","repo":"facebook/flow","slug":"workers-required-for-init","errorCode":null,"errorMessage":"workers required for init","messagePattern":"workers required for init","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"rust_port/crates/flow_codemods/src/utils/codemod_runner.rs","lineNumber":1194,"sourceCode":"    }\n\n    #[allow(unreachable_code)]\n    async fn init_run(\n        _genv: &Genv,\n        _roots: BTreeSet<FileKey>,\n    ) -> Result<\n        ((), (Self::Env, ResultList<Self::Accumulator>)),\n        flow_utils_concurrency::worker_cancel::WorkerCanceled,\n    > {\n        let options = &*_genv.options;\n        let workers = &_genv.workers;\n        let should_print_summary = options.profile;\n        let profiling = profiling_start(\"Codemod\", should_print_summary);\n        extract_flowlibs_or_exit(options);\n        let heap_transaction = ActiveTransaction::new(_genv.committed_heap.clone());\n        let transaction = heap_transaction.handle();\n        let options_arc = Arc::new(options.clone());\n        let pool = workers.as_ref().expect(\"workers required for init\");\n        let root = &options.root;\n        // let%lwt (_libs_ok, env) = Types_js.init ~profiling ~workers options in\n        let (env, _libs_ok) = flow_services_inference::type_service::init_from_scratch(\n            &options_arc,\n            pool,\n            &transaction,\n            root,\n        );\n        let file_options = &options.file_options;\n        let all = options.all;\n        let roots = get_target_filename_set(file_options, all, _roots);\n        let roots = TRC::expand_roots(&env, roots);\n        let env_files: BTreeSet<FileKey> = env.files.iter().cloned().collect();\n        let roots: BTreeSet<FileKey> = roots.intersection(&env_files).cloned().collect();\n        log_input_files(&roots);\n        let results =\n            TRC::merge_and_check(&env, workers, options, &profiling, roots, 0, &transaction)\n                .await?;","sourceCodeStart":1176,"sourceCodeEnd":1212,"githubUrl":"https://github.com/facebook/flow/blob/f88ac94bcf6992f5d5a158854d94613ebb92c6e6/rust_port/crates/flow_codemods/src/utils/codemod_runner.rs#L1176-L1212","documentation":"During codemod initialization the runner does `workers.as_ref().expect(\"workers required for init\")`. `Genv.workers` is built by `make_genv`, which creates a thread pool only when `options.max_workers > 0` and sets `None` when `max_workers == 0`. Typed codemod runners need that pool for `init_from_scratch`, so a zero-worker configuration panics here.","triggerScenarios":"Launching the codemod binary with `--max-workers 0` (or a config/env override that zeroes max_workers); building a Genv manually with max_workers=0 and then running a runner that requires a pool.","commonSituations":"Users passing `--max-workers 0` intending single-threaded execution; flag values copied from other tools where 0 means auto; tests embedding the runner with a minimal Genv.","solutions":["Run the codemod without `--max-workers 0`, or pass an explicit `--max-workers N` with N >= 1.","Trace where max_workers becomes 0 (CLI flag parsing, .flowconfig, environment) and fix the value.","If constructing the environment in code, use `make_genv` with max_workers >= 1 so a pool is created."],"exampleFix":"// before\nlet pool = workers.as_ref().expect(\"workers required for init\");\n\n// after\nlet Some(pool) = workers.as_ref() else {\n    eprintln!(\"codemod requires at least one worker (max_workers is 0); pass --max-workers >= 1\");\n    std::process::exit(2);\n};","handlingStrategy":"validation","validationCode":"// Before launching the codemod, reject a zero worker configuration\nif options.max_workers < 1 {\n    eprintln!(\"codemod requires max_workers >= 1 (got {})\", options.max_workers);\n    std::process::exit(2);\n}","typeGuard":null,"tryCatchPattern":"let Some(pool) = workers.as_ref() else {\n    eprintln!(\"max_workers is 0; pass --max-workers >= 1\");\n    std::process::exit(2);\n};","preventionTips":["Never pass --max-workers 0 to codemod binaries; omit the flag to use the default pool.","Validate max_workers at configuration load time, not deep in the runner.","When embedding the runner, build Genv via make_genv with max_workers >= 1."],"tags":["codemod","configuration","thread-pool","max-workers"],"backgroundTag":"invalid-configuration-value","analyzedSha":"f88ac94bcf6992f5d5a158854d94613ebb92c6e6","analyzedAt":"2026-08-20T10:41:37.992Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}