{"record":{"id":"5317a6ed006a98f5","repo":"windmill-labs/windmill","slug":"error-parsing-powershell-script","errorCode":null,"errorMessage":"Error parsing powershell script","messagePattern":"Error parsing powershell script","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/parsers/windmill-parser-bash/src/lib.rs","lineNumber":103,"sourceCode":"        };\n\n        Ok(MainArgSignature {\n            star_args: false,\n            star_kwargs: false,\n            args,\n            auto_kind: None,\n            has_preprocessor: None,\n            has_cmd_binding: if has_cmd_binding { Some(true) } else { None },\n            supports_should_process: if supports_should_process {\n                Some(true)\n            } else {\n                None\n            },\n\n            ..Default::default()\n        })\n    } else {\n        Err(anyhow!(\"Error parsing powershell script\".to_string()))\n    }\n}\n\nlazy_static::lazy_static! {\n    static ref RE_BASH: Regex = Regex::new(r#\"(?m)^(\\w+)=\"\\$(?:(\\d+)|\\{(\\d+)\\}|\\{(\\d+):-(.*)\\})\"(?:[\\t ]*)?(?:#.*)?\\r?$\"#).unwrap();\n}\n\nfn parse_bash_file(code: &str) -> anyhow::Result<Option<Vec<Arg>>> {\n    let mut hm: HashMap<i32, (String, Option<String>)> = HashMap::new();\n    for cap in RE_BASH.captures_iter(code) {\n        hm.insert(\n            cap.get(2)\n                .or(cap.get(3))\n                .or(cap.get(4))\n                .and_then(|x| x.as_str().parse::<i32>().ok())\n                .ok_or_else(|| anyhow!(\"Impossible to parse arg digit\"))?,\n            (\n                cap[1].to_string(),","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/backend/parsers/windmill-parser-bash/src/lib.rs#L85-L121","documentation":"`parse_powershell_sig` extracts a PowerShell script's parameters from a top-level `param(...)` block (including [Parameter(...)] attributes and [CmdletBinding()]). If the script has no param block matching the parser's grammar, it returns this error instead of a signature.","triggerScenarios":"Parsing a PowerShell script whose parameters aren't declared in a recognized top-level `param(...)` block — no param block at all, params only via $args, a param nested inside a function, or attribute formatting the parser's regexes don't cover.","commonSituations":"Scripts relying only on $args; param block placed after other statements (PowerShell requires param first anyway); advanced attribute syntax the parser doesn't support; empty or scaffold scripts.","solutions":["Declare script parameters in a top-level `param(...)` block at the very start of the script, one `[type]$name = $default` per line","If using [CmdletBinding()] or [Parameter(Mandatory)] attributes, keep them in the standard form the parser recognizes (see the parser's own tests for accepted forms)","Move any function-scoped param intended as a script parameter up to script scope","If no typed params are needed, define them through Windmill's script metadata/UI"],"exampleFix":"# before\nfunction Main($name) { ... }; Main -name $args[0]\n# after\nparam(\n    [string]$name = \"world\"\n)\n# body uses $name directly","handlingStrategy":"validation","validationCode":"// must have a top-level param block\n/^\\s*(\\[CmdletBinding\\(\\)\\]\\s*)?param\\s*\\(/.test(code.trimStart());","typeGuard":"function hasParseablePwshParams(code) {\n  return /^\\s*(\\[CmdletBinding\\(\\)\\]\\s*)?param\\s*\\(/m.test(code.trimStart());\n}","tryCatchPattern":"try { sig = parsePowershellSig(code); } catch (e) {\n  if (e.message === 'Error parsing powershell script') {\n    // use manually defined signature from script metadata\n  } else throw e;\n}","preventionTips":["Always start PowerShell scripts with a standard param(...) block","Keep [Parameter()] attribute syntax canonical (see parser tests for supported forms)","Don't nest intended script params inside functions","Preview the generated signature in the Windmill editor before saving"],"tags":["powershell","parser","signature","scripts"],"backgroundTag":"script-signature-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"}