windmill-labs/windmill · error

Error parsing code: {}

Error message

Error parsing code: {}

What it means

parse_php_signature parses the whole PHP file with the php-parser crate before scanning for the entrypoint function (default 'main'). Any syntax error the underlying PHP parser reports — message included via {} — is rethrown as 'Error parsing code: ...'.

Source

Thrown at backend/parsers/windmill-parser-php/src/lib.rs:52

            },
            Literal::Float(f) => match f.value.to_string().parse() {
                Ok(i) => Some(Value::Number(i)),
                Err(_) => None,
            },
        },
        Expression::Bool(b) => Some(Value::Bool(b.value)),
        _ => None,
    }
}

pub fn parse_php_signature(
    code: &str,
    override_entrypoint: Option<String>,
) -> anyhow::Result<MainArgSignature> {
    let entrypoint_fn_name = override_entrypoint.unwrap_or("main".to_string());

    let ast = parser::parse(code)
        .map_err(|e| anyhow::anyhow!("Error parsing code: {}", e.to_string()))?;

    let mut entrypoint_params = None;
    let mut has_preprocessor = None;
    for node in ast.into_iter() {
        match node {
            Statement::Function(FunctionStatement {
                name,
                parameters: FunctionParameterList { parameters, .. },
                ..
            }) => {
                let fn_name = name.to_string();

                if has_preprocessor.is_none() && fn_name == "preprocessor" {
                    has_preprocessor = Some(true);
                }

                if entrypoint_params.is_none() && fn_name == entrypoint_fn_name {
                    entrypoint_params = Some(parameters);

View on GitHub (pinned to e474e8803c)

Solutions

  1. Read the wrapped message after 'Error parsing code:' — it names the exact line/column of the PHP syntax error.
  2. Fix the syntax error at the reported location in the PHP file.
  3. Remove non-PHP content (HTML blocks, templating placeholders) or ensure the file is a valid .php script the parser accepts.
  4. Verify the syntax with 'php -l file.php' locally; the windmill parser tracks the same grammar family.
  5. Check that syntax features used (enums, readonly, named args) match the PHP version the parser supports.

Example fix

// before
function main($x) {
  return $x +
}

// after
function main($x) {
  return $x + 1;
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Validate PHP syntax before parsing (requires php on PATH)
const { execSync } = require('child_process');
function validatePhpSyntax(code) {
  try {
    execSync('php -l', { input: code, stdio: 'pipe' });
  } catch (e) {
    throw new Error('PHP syntax invalid: ' + e.stderr.toString());
  }
}

Try / catch

try {
  const sig = await parsePhpSignature(code, entrypoint);
} catch (e) {
  if (String(e.message).startsWith('Error parsing code:')) {
    const detail = String(e.message).replace('Error parsing code:', '').trim();
    throw new Error(`Fix PHP syntax: ${detail}`);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling parse_php_signature with code containing PHP syntax errors: unterminated strings, missing semicolons, unclosed braces, PHP version-incompatible syntax (e.g. enums on PHP 7), or non-PHP content passed as code.

Common situations: Deploying a script written for a newer PHP version than the embedded parser supports; a copy-pasted snippet with template placeholders ({{ ... }}) left in; files mixing HTML with PHP where the pure-PHP parser chokes.

Related errors


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