{"record":{"id":"58d7b1530825d16a","repo":"windmill-labs/windmill","slug":"x-to-string-parse-source-error-dynamic-message","errorCode":null,"errorMessage":"x.to_string() (parse_source error, dynamic message)","messagePattern":"x\\.to_string\\(\\) \\(parse_source error, dynamic message\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/parsers/windmill-parser-go/src/lib.rs","lineNumber":18,"sourceCode":"#![allow(non_snake_case)] // TODO: switch to parse_* function naming\n\nuse gosyn::{\n    ast::{Declaration, Expression, Field, Ident, StructType},\n    parse_source,\n};\nuse itertools::Itertools;\n\nuse regex::Regex;\nuse windmill_parser::{Arg, MainArgSignature, ObjectProperty, ObjectType, Typ};\n\nlazy_static::lazy_static! {\n    pub static ref REQUIRE_PARSE: Regex = Regex::new(r\"//require (.*)\\n\").unwrap();\n}\n\npub fn parse_go_sig(code: &str) -> anyhow::Result<MainArgSignature> {\n    let filtered_code = filter_non_main(code);\n    let file = parse_source(&filtered_code).map_err(|x| anyhow::anyhow!(x.to_string()))?;\n    if let Some(func) = file.decl.iter().find_map(|x| match x {\n        Declaration::Function(func) if &func.name.name == \"main\" => Some(func),\n        _ => None,\n    }) {\n        let args = func\n            .typ\n            .params\n            .list\n            .iter()\n            .flat_map(|param| {\n                let (otyp, typ) = parse_go_typ(&param.typ);\n                // a single field can declare several like-typed params: `func main(a, b string)`\n                let names: Vec<String> = if param.name.is_empty() {\n                    vec![\"\".to_string()]\n                } else {\n                    param.name.iter().map(|y| y.name.to_string()).collect()\n                };\n                names.into_iter().map(move |name| Arg {","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/backend/parsers/windmill-parser-go/src/lib.rs#L1-L36","documentation":"parse_go_sig filters the script to its main portion and hands it to gosyn::parse_source; any gosyn parse error (Go syntax error) is stringified and rewrapped with anyhow. The message shown to users is therefore the raw Go parser error (e.g. 'expected ..., found ...'), meaning the Go script failed to parse so its main-function signature cannot be extracted.","triggerScenarios":"Deploying/previewing a Go Windmill script whose source has Go syntax errors — unbalanced braces, missing closing brace on func main, stray characters, template placeholders left unsubstituted, or code that gosyn (which may lag the Go language) cannot parse.","commonSituations":"Generics-heavy Go code with syntax gosyn predates; scripts edited externally and pasted with corruption; incomplete code saved mid-edit; non-Go text pasted into a Go script.","solutions":["Run `gofmt -e` or `go vet` on the script body locally to locate the syntax error and fix it","Check for placeholders or half-deleted code around the line/column gosyn reports","If the code uses very new Go syntax that fails only here, simplify it or upgrade the gosyn dependency in windmill-parser-go","Ensure the file is valid `package main` with `func main()` as filter_non_main expects"],"exampleFix":"// before\nfunc main( {\n    fmt.Println(\"hi\")\n// after\nfunc main() {\n    fmt.Println(\"hi\")\n}","handlingStrategy":"try-catch","validationCode":"// Validate Go syntax before submitting:\n//   gofmt -e script.go   (reports the first syntax error)\n// or locally: go vet / go build on a scratch copy","typeGuard":null,"tryCatchPattern":"match parse_go_sig(code) {\n    Ok(sig) => sig,\n    Err(e) => {\n        // e already carries gosyn's message (expected X, found Y) — surface it verbatim\n        // to point the author at the offending line/column\n        Err(anyhow!(\"Go script syntax error: {e}\"))\n    }\n}","preventionTips":["Run gofmt -e on the script body before deploying","Ensure the script declares `package main` and `func main()`","Avoid Go syntax newer than the vendored gosyn version (check generics usage)","Never paste non-Go content into a Go script slot"],"tags":["go","syntax-error","gosyn","parser"],"backgroundTag":"go-syntax-parse-failed","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"}