{"record":{"id":"145f879aa72bc146","repo":"facebook/relay","slug":"failed-to-run-locate-command","errorCode":null,"errorMessage":"Failed to run locate command: {}","messagePattern":"Failed to run locate command: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/crates/relay-bin/src/main.rs","lineNumber":625,"sourceCode":"    }\n\n    fn resolve_field_definition(\n        &self,\n        project_name: String,\n        parent_type: String,\n        field_info: Option<FieldSchemaInfo>,\n    ) -> Result<Option<FieldDefinitionSourceInfo>, String> {\n        let entity_name = match field_info {\n            Some(field_info) => format!(\"{}.{}\", parent_type, field_info.name),\n            None => parent_type,\n        };\n        let result = Command::new(&self.locate_command)\n            .arg(project_name)\n            .arg(entity_name)\n            .output()\n            .map_err(|e| format!(\"Failed to run locate command: {}\", e))?;\n\n        let result = String::from_utf8(result.stdout).expect(\"Failed to parse output\");\n\n        // Parse file_path:line_number:column_number\n        let result_trimmed = result.trim();\n        let result = result_trimmed.split(':').collect::<Vec<_>>();\n        if result.len() != 3 {\n            return Err(format!(\n                \"Result '{}' did not match expected format. Please return 'file_path:line_number:column_number'\",\n                result_trimmed\n            ));\n        }\n        let file_path = result[0];\n        let line_number = result[1].parse::<u64>().unwrap() - 1;\n        let column_number = result[2].parse::<u64>().unwrap_or(1_u64) - 1;\n\n        Ok(Some(FieldDefinitionSourceInfo {\n            file_path: file_path.to_string(),\n            line_number,\n            column_number,","sourceCodeStart":607,"sourceCodeEnd":643,"githubUrl":"https://github.com/facebook/relay/blob/668b1b85e06261aa3b58dabfc51f8b5524a70955/compiler/crates/relay-bin/src/main.rs#L607-L643","documentation":"resolve_field_definition spawns the configured locate_command with project_name and entity_name as arguments. If the process cannot be spawned or awaited (binary missing, not executable, IO error), the error is wrapped with this 'Failed to run locate command: {}' message and returned as a string error.","triggerScenarios":"Calling the field-resolution feature when locate_command points to a non-existent binary, lacks execute permission, or the OS refuses to fork/exec.","commonSituations":"Configured locate tool not installed on the machine; script path relative to a different working directory; missing shebang or +x bit; PATH differences in editors/IDEs launching relay.","solutions":["Verify the locate command exists and runs: run it manually with the same two arguments","Make the script executable (chmod +x) and give it a proper shebang","Use an absolute path for the command in the relay config","Check PATH in the environment that launches relay (IDE-integrated terminals often differ)"],"exampleFix":"// before (relay config)\n\"locateCommand\": \"scripts/find-field\"\n// after (absolute, executable)\n\"locateCommand\": \"/absolute/path/to/scripts/find-field\"  # + chmod +x","handlingStrategy":"validation","validationCode":"const { execFileSync } = require('child_process');\nfunction assertLocateRunnable(cmd, ...args) {\n  try { execFileSync(cmd, args, { stdio: 'ignore' }); }\n  catch (e) {\n    if (e.code === 'ENOENT') throw new Error(`Locate command not found: ${cmd}`);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  resolveFieldDefinition(project, entity);\n} catch (e) {\n  if (/Failed to run locate command/.test(e.message)) {\n    console.error('Ensure the locate binary exists, is executable, and is on PATH.');\n  } else throw e;\n}","preventionTips":["Use absolute paths for the locate command in relay config","chmod +x and shebang-check custom scripts","Verify PATH in IDE/CI launch environments","Smoke-test the command with the same arguments relay passes"],"tags":["process-spawn","cli","locate-command","environment"],"backgroundTag":"command-not-found","analyzedSha":"668b1b85e06261aa3b58dabfc51f8b5524a70955","analyzedAt":"2026-09-02T19:57:20.783Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}