{"record":{"id":"d608e480f284b4e5","repo":"facebook/relay","slug":"failed-to-build-programs","errorCode":null,"errorMessage":"Failed to build programs","messagePattern":"Failed to build programs","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/crates/relay-codemod/src/codemod.rs","lineNumber":61,"sourceCode":"\n#[derive(Args, Debug, Clone)]\npub struct MarkDangerousConditionalFragmentSpreadsArgs {\n    /// Specify a percentage of fragments to codemod. If a number is provided,\n    /// the first n percentage of fragments will be codemodded. If a range (`20-30`) is\n    /// provided, then fragments between the start and end of the range will be codemodded.\n    #[clap(long, short, value_parser=valid_percent, default_value = \"100\")]\n    pub rollout_percentage: FeatureFlag,\n}\n\npub async fn run_codemod(\n    programs: CompilerResult<Vec<Arc<Programs>>>,\n    root_dir: PathBuf,\n    codemod: AvailableCodemod,\n) -> Result<(), std::io::Error> {\n    match &codemod {\n        AvailableCodemod::MarkDangerousConditionalFragmentSpreads(opts) => {\n            run_codemod_impl(\n                programs.expect(\"Failed to build programs\"),\n                root_dir,\n                |programs: &Arc<Programs>| {\n                    fragment_alias_directive(&programs.source, &opts.rollout_percentage).map(|_| ())\n                }, // Codemods don't return anything for OK,\n                format!(\"{codemod:?}\").as_str(),\n            )\n            .await\n        }\n        AvailableCodemod::RemoveUnnecessaryRequiredDirectives => {\n            run_codemod_impl(\n                programs.expect(\"Failed to build programs\"),\n                root_dir,\n                |programs: &Arc<Programs>| disallow_required_on_non_null_field(&programs.reader),\n                format!(\"{codemod:?}\").as_str(),\n            )\n            .await\n        }\n        AvailableCodemod::FixAll => {","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/facebook/relay/blob/668b1b85e06261aa3b58dabfc51f8b5524a70955/compiler/crates/relay-codemod/src/codemod.rs#L43-L79","documentation":"run_codemod receives an Option<Arc<Programs>> that was produced by an earlier build step. For MarkDangerousConditionalFragmentSpreads it unwraps with .expect(\"Failed to build programs\"), meaning the programs failed to construct earlier (compile errors, config problems) and the codemod cannot run.","triggerScenarios":"Running the mark-dangerous-conditional-fragment-spreads codemod when the preceding program build returned None/Err, so the Option is unwrapped via expect.","commonSituations":"GraphQL syntax errors in the project that abort program construction; schema file changes that no longer parse; codemod run before fixing a broken compilation state.","solutions":["Run `relay build` (or the compiler) first and fix all reported GraphQL/schema errors until compilation succeeds","Re-run the codemod after the build succeeds","If running programmatically, check the build result before calling run_codemod instead of relying on expect"],"exampleFix":"// before\nrelay codemod mark-dangerous-conditional-fragment-spreads   // broken schema\n// after\nrelay build            # fix errors it reports\nrelay codemod mark-dangerous-conditional-fragment-spreads","handlingStrategy":"try-catch","validationCode":"// Run the compiler first and confirm success before codemod\nconst build = spawnSync('relay', ['build'], { stdio: 'inherit' });\nif (build.status !== 0) throw new Error('Fix compiler errors before running codemods');","typeGuard":null,"tryCatchPattern":"try {\n  await runCodemod(rootDir, codemod, programs);\n} catch (e) {\n  if (/Failed to build programs/.test(e.message)) {\n    console.error('Programs failed to build; run `relay build` and fix GraphQL/schema errors first.');\n  } else throw e;\n}","preventionTips":["Always run a successful `relay build` before codemods","Fix schema/GraphQL parse errors before mutating sources","Keep generated artifacts in sync with the schema","Programmatically check build results instead of relying on unwrapping"],"tags":["codemod","panic","build","graphql"],"backgroundTag":"program-build-failed","analyzedSha":"668b1b85e06261aa3b58dabfc51f8b5524a70955","analyzedAt":"2026-09-02T19:57:20.783Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}