{"record":{"id":"546502583dfb2a11","repo":"windmill-labs/windmill","slug":"failed-to-parse-code","errorCode":null,"errorMessage":"Failed to parse code","messagePattern":"Failed to parse code","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/parsers/windmill-parser-java/src/lib.rs","lineNumber":32,"sourceCode":"#[derive(Debug)]\npub struct JavaMainSigMeta {\n    pub is_public: bool,\n    pub returns_void: bool,\n    pub class_name: Option<String>,\n    pub main_sig: MainArgSignature,\n}\n\npub fn parse_java_sig_meta(code: &str) -> anyhow::Result<JavaMainSigMeta> {\n    let mut parser = tree_sitter::Parser::new();\n    let language = tree_sitter_java::LANGUAGE;\n    parser\n        .set_language(&language.into())\n        .map_err(|e| anyhow!(\"Error setting Java 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    // Traverse the AST to find the Main method signature\n    let main_sig = find_main_signature(root_node, code);\n    let auto_kind = if main_sig.is_none() {\n        Some(\"lib\".to_string())\n    } else {\n        None\n    };\n    let mut is_public = false;\n    let mut returns_void = false;\n    let mut class_name = None;\n\n    let mut args = vec![];\n    if let Some((sig, name)) = main_sig {\n        class_name = name;\n        for sig_node in sig.children(&mut sig.walk()) {\n            if sig_node.kind() == \"modifier\" && sig_node.utf8_text(code.as_bytes())? == \"public\" {","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/backend/parsers/windmill-parser-java/src/lib.rs#L14-L50","documentation":"This error comes from parse_java_sig_meta in windmill-parser-java. The tree-sitter Java parser's `parse()` method returns Option<Tree>, and it only returns None when the parser could not produce a tree at all — in practice this means the tree-sitter Parser object failed to load/initialize its language (an internal, near-impossible condition once the grammar compiles) or the input could not be processed by the parser. It is a defensive guard, not a syntax-error signal: even invalid Java normally yields a tree with ERROR nodes rather than None.","triggerScenarios":"Calling parse_java_signature or parse_java_sig_meta on any &str when tree_sitter::Parser::parse returns None. In this crate the language is set from the statically linked tree_sitter_java grammar, so a None return is not caused by malformed Java source; it indicates the parser/language failed to initialize (e.g. incompatible tree-sitter runtime vs grammar ABI version after a dependency upgrade, or a corrupted/WASM build of the parser crate).","commonSituations":"Upgrading tree-sitter or tree-sitter-java so the compiled grammar's ABI version no longer matches the tree-sitter runtime (language fails to attach and parse misbehaves); building the crate for an unsupported target (wasm32) where the C grammar doesn't load correctly; running on a broken/untested platform build where the tree-sitter FFI can't initialize.","solutions":["Run `cargo update -p tree-sitter` and re-check tree-sitter-java / tree-sitter versions in backend/parsers/windmill-parser-java/Cargo.toml; align both to compatible versions and rebuild from scratch (`cargo clean -p windmill-parser-java`).","Rebuild the crate for your target (a stale or partially-built artifact can break the FFI grammar load): `cargo build` from backend/ after a clean of this package.","If on wasm32 or another exotic target, test the same parse on the host target to confirm it is a target-specific grammar-loading problem, then pin the working tree-sitter version.","If it persists, file an issue with the code input and dependency versions — the parser returning None for real input indicates a grammar/runtime bug, not a user input problem."],"exampleFix":"// before (Cargo.toml after a mismatched upgrade)\ntree-sitter = \"0.25\"\ntree-sitter-java = \"0.20\" // ABI mismatch -> set_language/parse misbehaves\n\n// after: use a tree-sitter-java version built for your tree-sitter runtime\ntree-sitter = \"0.25\"\ntree-sitter-java = \"0.23\" // matching ABI, parse() returns a tree again","handlingStrategy":"try-catch","validationCode":"// This failure is not input-dependent, so validate the environment instead:\n// ensure the parser builds a tree on a known-good probe before trusting it\nfn parser_healthy() -> bool {\n    parse_java_signature(\"class Main { public static void main() {} }\").is_ok()\n}","typeGuard":null,"tryCatchPattern":"match parse_java_signature(code) {\n    Ok(sig) => sig,\n    Err(e) if e.to_string().contains(\"Failed to parse code\") => {\n        // parser/language init failure, not bad input: fall back or abort deploy\n        Default::default()\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Pin tree-sitter and tree-sitter-java to a known-compatible pair in Cargo.toml and update them together.","Add a startup smoke test that parses a minimal `main` class; run it in CI for every dependency bump.","Rebuild cleanly (cargo clean of the parser crate) after changing target platforms or toolchains.","Do not assume this error reflects bad user code — route it to internal-error telemetry, not user-facing validation messages."],"tags":["rust","tree-sitter","java","parser"],"backgroundTag":"tree-sitter-grammar-load-failure","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}