{"record":{"id":"ccb89f98606e1eec","repo":"facebook/relay","slug":"diagnostics","errorCode":null,"errorMessage":"{diagnostics}","messagePattern":"\\{diagnostics\\}","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/crates/graphql-ir-diff/src/lib.rs","lineNumber":763,"sourceCode":"            }\n            _ => (),\n        }\n    }\n}\n\npub fn collect_normalized_tree(program: &Program) -> Rc<NormalizedTree> {\n    let mut collector = NormalizedTreeCollector::new(&program.schema);\n    collector.visit_program(program);\n    assert!(\n        collector.stack.len() == 1,\n        \"stack must be size 1 post visit\"\n    );\n    collector.stack.last().unwrap().clone()\n}\n\npub fn format_document(document: &str) -> Result<String> {\n    let ast = parse_executable(document, SourceLocationKey::generated())\n        .map_err(|diagnostics| anyhow::anyhow!(diagnostics.iter().join(\"\\n\")))?;\n\n    let formatted: String = ast\n        .definitions\n        .iter()\n        .map(print_executable_definition_ast)\n        .collect::<Vec<_>>()\n        .join(\"\\n\\n\");\n\n    Ok(formatted)\n}\n\npub fn parse(schema: Arc<SDLSchema>, document: &str) -> Result<Program> {\n    let ast = parse_executable(document, SourceLocationKey::generated())\n        .map_err(|diagnostics| anyhow::anyhow!(diagnostics.iter().join(\"\\n\")))?;\n    let ir = build_ir_with_extra_features(\n        &schema,\n        &ast.definitions,\n        &BuilderOptions {","sourceCodeStart":745,"sourceCodeEnd":781,"githubUrl":"https://github.com/facebook/relay/blob/668b1b85e06261aa3b58dabfc51f8b5524a70955/compiler/crates/graphql-ir-diff/src/lib.rs#L745-L781","documentation":"format_document parses a GraphQL executable document string before pretty-printing it. If parse_executable produces GraphQL diagnostics, they are joined with newlines into an anyhow error. It means the input string is not a syntactically valid GraphQL executable document, so formatting cannot proceed.","triggerScenarios":"Calling format_document(document) with text containing GraphQL syntax errors — unbalanced braces, invalid characters, misplaced tokens, non-executable garbage text.","commonSituations":"Diff tooling feeding test snapshots or fixture files that contain intentional invalid GraphQL; files saved with wrong encoding; documents interpolated with broken template strings in build scripts.","solutions":["Read the joined diagnostics in the error message; they pinpoint file-less generated-source locations of each syntax error.","Validate/fix the GraphQL syntax of the document before formatting (e.g. run it through a linter or editor GraphQL plugin).","Ensure the input is a document of executable definitions (query/mutation/subscription/fragment), not a schema/type-system document.","Check for stray interpolation artifacts (unescaped braces, placeholder text) in generated documents."],"exampleFix":"// before\nformat_document(\"query { user { name }\")  // unbalanced brace\n// after\nformat_document(\"query { user { name } }\")","handlingStrategy":"try-catch","validationCode":"// Best-effort pre-check: parse before formatting\nmatch parse_executable(document, SourceLocationKey::generated()) {\n    Ok(_) => format_document(document)?,\n    Err(diags) => eprintln!(\"invalid document: {}\", diags.iter().join(\"\\n\")),\n}","typeGuard":null,"tryCatchPattern":"match format_document(doc) {\n    Ok(formatted) => formatted,\n    Err(e) => { log::error!(\"format_document failed: {e}\"); fallback_raw(doc) }\n}","preventionTips":["Lint GraphQL fixtures in CI before running format/diff tools.","Ensure inputs are executable definitions, not type-system SDL.","Escape generated documents when interpolating into strings."],"tags":["graphql","parse-error","diagnostics","formatting"],"backgroundTag":"graphql-parse-error","analyzedSha":"668b1b85e06261aa3b58dabfc51f8b5524a70955","analyzedAt":"2026-09-02T19:57:20.783Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}