{"record":{"id":"f0d06adbd6187ae4","repo":"windmill-labs/windmill","slug":"failed-to-parse-code-f0d06a","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-ruby/src/lib.rs","lineNumber":26,"sourceCode":"use regex::Regex;\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_ruby_sig_meta(code: &str) -> anyhow::Result<MainArgSignature> {\n    let mut parser = tree_sitter::Parser::new();\n    let language = tree_sitter_ruby::LANGUAGE;\n    parser\n        .set_language(&language.into())\n        .map_err(|e| anyhow!(\"Error setting Ruby as language: {e}\"))?;\n\n    // Parse code\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    root_node.clone().to_string();\n    // Traverse the AST to find the Main method signature\n    let args = find_main_signature(root_node, code)?;\n    let auto_kind = if args.is_none() {\n        Some(\"lib\".to_string())\n    } else {\n        None\n    };\n\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,\n        ..Default::default()","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/backend/parsers/windmill-parser-ruby/src/lib.rs#L8-L44","documentation":"Inside `parse_ruby_sig_meta`, `parser.parse(code, None)` returning `None` is mapped to `anyhow!(\"Failed to parse code\")`. With a language successfully set, `parse` practically returns `None` only when no language is loaded, so this indicates a parser-configuration problem rather than syntactically invalid Ruby.","triggerScenarios":"Calling `parse_ruby_sig_meta` when the parser's `parse` yields `None` — i.e. no language loaded or an external cancellation triggered — during signature extraction of a Ruby script.","commonSituations":"Code paths that bypass `set_language`; reuse of a reset parser instance; forks where set_language failure is ignored with `let _ =`.","solutions":["Verify `set_language(&tree_sitter_ruby::LANGUAGE.into())?` runs and propagates its error before parse","Construct a fresh `Parser` per call instead of reusing one whose language may have been reset","Improve the message to include why parse returned None for debuggability"],"exampleFix":"// before\n.ok_or(anyhow!(\"Failed to parse code\"))?;\n// after\n.ok_or_else(|| anyhow!(\"Failed to parse Ruby code: parser returned None (no language set?)\"))?;","handlingStrategy":"validation","validationCode":"// Validate inputs and parser setup before relying on signature extraction:\nassert!(!code.trim().is_empty(), \"Ruby source must be non-empty\");\n// ensure language loads with the same parser setup the library uses:\nlet mut p = tree_sitter::Parser::new();\np.set_language(&tree_sitter_ruby::LANGUAGE.into()).expect(\"ruby grammar\");","typeGuard":null,"tryCatchPattern":"match parse_ruby_sig_meta(code) {\n    Ok(m) => m,\n    Err(e) if e.to_string() == \"Failed to parse code\" => {\n        // parser had no language: log infra error, do not blame user's script\n        Err(anyhow!(\"Ruby signature parse returned no tree (infra)\"))\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Construct a fresh Parser inside each parse function","Propagate set_language errors — never `let _ =` them","Add distinguishing context to bare 'Failed to parse code' messages"],"tags":["rust","tree-sitter","ruby","parser"],"backgroundTag":"parser-not-configured","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"}