{"record":{"id":"85cda6226a7d6036","repo":"windmill-labs/windmill","slug":"error-parsing-code-85cda6","errorCode":null,"errorMessage":"Error parsing code: {}","messagePattern":"Error parsing code: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/parsers/windmill-parser-py-asset/src/lib.rs","lineNumber":12,"sourceCode":"use rustpython_ast::{Constant, Expr, ExprConstant, Visitor};\nuse rustpython_parser::{ast::Suite, Parse};\nuse std::collections::HashMap;\nuse windmill_parser::asset_parser::{\n    asset_was_used, merge_assets, parse_asset_syntax, parse_pipeline_annotations, AssetKind,\n    AssetUsageAccessType, ParseAssetsOutput, ParseAssetsResult,\n};\nuse AssetUsageAccessType::*;\n\npub fn parse_assets(input: &str) -> anyhow::Result<ParseAssetsOutput> {\n    let ast = Suite::parse(input, \"main.py\")\n        .map_err(|e| anyhow::anyhow!(\"Error parsing code: {}\", e.to_string()))?;\n\n    let mut assets_finder = AssetsFinder { assets: vec![], var_identifiers: HashMap::new() };\n    ast.into_iter()\n        .for_each(|stmt| assets_finder.visit_stmt(stmt));\n\n    for (kind, path, _) in assets_finder.var_identifiers.into_values() {\n        // if a db = wmill.datatable() was never used (e.g db.query(...)),\n        // we still want to register the asset as unknown access type\n        if asset_was_used(&assets_finder.assets, (kind, &path)) == false {\n            assets_finder.assets.push(ParseAssetsResult {\n                kind,\n                path,\n                access_type: None,\n                columns: None,\n            });\n        }\n    }\n","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/backend/parsers/windmill-parser-py-asset/src/lib.rs#L1-L30","documentation":"parse_assets in windmill-parser-py-asset parses the entire Python file with the ruff python_ast Suite::parse before walking it for windmill asset references (s3:// URIs etc.). If the file is not syntactically valid Python, the parse error is wrapped as 'Error parsing code: ...'.","triggerScenarios":"Calling parse_assets on Python source with syntax errors, Python-version-mismatched syntax (e.g. match statements parsed with an older target), or non-Python content passed in as the script body.","commonSituations":"Scripts generated by templates with unfilled placeholders, Python 2 style print statements, truncated files from failed writes, or pasted code with smart quotes / invisible characters.","solutions":["Read the wrapped message for the exact line/column of the Python syntax error and fix it there.","Validate locally with 'python -m py_compile main.py' before deploying.","Remove leftover template placeholders and smart quotes/invisible characters from pasted code.","Ensure the syntax used matches the Python version the ruff-based parser targets."],"exampleFix":"// before\nprint \"hello\"\n\n// after\nprint(\"hello\")","handlingStrategy":"validation","validationCode":"import subprocess, sys, tempfile, os\ndef validate_python_syntax(code: str) -> None:\n    with tempfile.NamedTemporaryFile('w', suffix='.py', delete=False) as f:\n        f.write(code); path = f.name\n    try:\n        subprocess.run([sys.executable, '-m', 'py_compile', path], check=True,\n                       capture_output=True)\n    except subprocess.CalledProcessError as e:\n        raise SystemExit(f'Python syntax invalid:\\n{e.stderr.decode()}')\n    finally:\n        os.unlink(path)","typeGuard":null,"tryCatchPattern":"try:\n    out = parse_assets(code)\nexcept Exception as e:\n    if 'Error parsing code:' in str(e):\n        raise RuntimeError(f'Fix Python syntax before asset analysis: {e}') from e\n    raise","preventionTips":["Run py_compile or ruff check on the script before deploying","Save files as UTF-8 without BOM; avoid smart quotes from rich-text editors","Ensure generated scripts have no unfilled template placeholders","Verify the syntax matches the Python version the parser targets"],"tags":["python","parser","syntax-error","assets"],"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"}