windmill-labs/windmill · error

Failed to parse code

Error message

Failed to parse code

What it means

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.

Source

Thrown at backend/parsers/windmill-parser-java/src/lib.rs:32

#[derive(Debug)]
pub struct JavaMainSigMeta {
    pub is_public: bool,
    pub returns_void: bool,
    pub class_name: Option<String>,
    pub main_sig: MainArgSignature,
}

pub fn parse_java_sig_meta(code: &str) -> anyhow::Result<JavaMainSigMeta> {
    let mut parser = tree_sitter::Parser::new();
    let language = tree_sitter_java::LANGUAGE;
    parser
        .set_language(&language.into())
        .map_err(|e| anyhow!("Error setting Java as language: {e}"))?;

    // Parse code
    let tree = parser
        .parse(code, None)
        .ok_or(anyhow!("Failed to parse code"))?;
    let root_node = tree.root_node();

    // Traverse the AST to find the Main method signature
    let main_sig = find_main_signature(root_node, code);
    let auto_kind = if main_sig.is_none() {
        Some("lib".to_string())
    } else {
        None
    };
    let mut is_public = false;
    let mut returns_void = false;
    let mut class_name = None;

    let mut args = vec![];
    if let Some((sig, name)) = main_sig {
        class_name = name;
        for sig_node in sig.children(&mut sig.walk()) {
            if sig_node.kind() == "modifier" && sig_node.utf8_text(code.as_bytes())? == "public" {

View on GitHub (pinned to e474e8803c)

Solutions

  1. 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`).
  2. 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.
  3. 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.
  4. 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.

Example fix

// before (Cargo.toml after a mismatched upgrade)
tree-sitter = "0.25"
tree-sitter-java = "0.20" // ABI mismatch -> set_language/parse misbehaves

// after: use a tree-sitter-java version built for your tree-sitter runtime
tree-sitter = "0.25"
tree-sitter-java = "0.23" // matching ABI, parse() returns a tree again
Defensive patterns

Strategy: try-catch

Validate before calling

// This failure is not input-dependent, so validate the environment instead:
// ensure the parser builds a tree on a known-good probe before trusting it
fn parser_healthy() -> bool {
    parse_java_signature("class Main { public static void main() {} }").is_ok()
}

Try / catch

match parse_java_signature(code) {
    Ok(sig) => sig,
    Err(e) if e.to_string().contains("Failed to parse code") => {
        // parser/language init failure, not bad input: fall back or abort deploy
        Default::default()
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Related errors


AI-assisted analysis of windmill-labs/windmill@e474e8803c (2026-09-03). Data as JSON: /api/errors/546502583dfb2a11. Report an issue: GitHub.