{"record":{"id":"ef9153f69cddca80","repo":"windmill-labs/windmill","slug":"failed-to-parse-code-ef9153","errorCode":null,"errorMessage":"Failed to parse code","messagePattern":"Failed to parse code","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/parsers/windmill-parser-r/src/lib.rs","lineNumber":23,"sourceCode":"\nuse anyhow::anyhow;\nuse serde_json::Value;\nuse tree_sitter::Node;\nuse tree_sitter::Range;\nuse windmill_parser::json_to_typ;\nuse windmill_parser::Arg;\nuse windmill_parser::MainArgSignature;\n\npub fn parse_r_sig_meta(code: &str) -> anyhow::Result<MainArgSignature> {\n    let mut parser = tree_sitter::Parser::new();\n    let language = tree_sitter_r::LANGUAGE;\n    parser\n        .set_language(&language.into())\n        .map_err(|e| anyhow!(\"Error setting R as language: {e}\"))?;\n\n    let tree = parser\n        .parse(code, None)\n        .ok_or(anyhow!(\"Failed to parse code\"))?;\n    let root_node = tree.root_node();\n\n    let args = find_main_signature(root_node, code)?;\n    let main_sig = MainArgSignature {\n        star_args: false,\n        star_kwargs: false,\n        args: args.unwrap_or_default(),\n        has_preprocessor: None,\n        auto_kind: None,\n        ..Default::default()\n    };\n\n    Ok(main_sig)\n}\n\npub fn parse_r_signature(code: &str) -> anyhow::Result<MainArgSignature> {\n    Ok(parse_r_sig_meta(code)?)\n}","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/backend/parsers/windmill-parser-r/src/lib.rs#L5-L41","documentation":"After set_language succeeds, parse_r_sig_meta calls parser.parse(code, None) to build the R syntax tree. tree-sitter's parse returns Option<Tree> and is None only when the parser could not allocate or the parser is in an invalid state — the code maps that to 'Failed to parse code'. Unlike most parsers, this does NOT fire for syntactically invalid R code (tree-sitter produces an error-containing tree instead).","triggerScenarios":"Calling parse_r_signature when the underlying tree-sitter parse call returns None: out-of-memory during tree construction, or a parser left in a bad state after set_language — environmental/resource conditions, not R syntax errors.","commonSituations":"Parsing under severe memory pressure; extremely large R files exceeding allocation limits; a broken grammar load that set_language silently accepted in some builds.","solutions":["Retry the operation — the failure is typically transient (allocation), unlike a syntax error.","Check memory availability where the backend runs; reduce the size of the R file if it is extraordinarily large.","Verify the tree-sitter-r grammar loads correctly (if error 828 was patched around, this may be the follow-on symptom).","If reproducible on small inputs, file a backend issue with the code snippet — the parser should never return None for normal scripts."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// tree-sitter returns None only on allocation/invalid-state failures, so no\n// content pre-check helps; guard on size and retry:\nfunction canAttemptRParse(code) {\n  if (code.length > 5_000_000) throw new Error('R file too large for signature parsing');\n  return true;\n}","typeGuard":null,"tryCatchPattern":"match parse_r_signature(code) {\n    Err(e) if e.to_string().contains(\"Failed to parse code\") => {\n        // transient (allocation) — retry once before failing\n        parse_r_signature(code)\n    }\n    other => other,\n}","preventionTips":["Retry once on this specific message — it is usually transient, unlike a syntax error","Avoid extraordinarily large R files in signature parsing","Ensure adequate memory where the backend runs","If reproducible on small inputs, file a backend issue with the snippet"],"tags":["r","tree-sitter","parse-failure","resource"],"backgroundTag":"syntax-error","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}