{"record":{"id":"5831d30074156ac3","repo":"windmill-labs/windmill","slug":"error-parsing-bash-script","errorCode":null,"errorMessage":"Error parsing bash script","messagePattern":"Error parsing bash script","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/parsers/windmill-parser-bash/src/lib.rs","lineNumber":28,"sourceCode":"use serde_json::json;\n\nuse std::{collections::HashMap, str::FromStr};\nuse windmill_parser::{Arg, MainArgSignature, ObjectType, Typ};\n\npub fn parse_bash_sig(code: &str) -> anyhow::Result<MainArgSignature> {\n    let parsed = parse_bash_file(&code)?;\n    if let Some(x) = parsed {\n        let args = x;\n        Ok(MainArgSignature {\n            star_args: false,\n            star_kwargs: false,\n            args,\n            auto_kind: None,\n            has_preprocessor: None,\n            ..Default::default()\n        })\n    } else {\n        Err(anyhow!(\"Error parsing bash script\".to_string()))\n    }\n}\n\n/// PowerShell common parameter names that are automatically added by [CmdletBinding()].\n/// These should be filtered from the parsed signature since they are not user-defined.\nconst POWERSHELL_COMMON_PARAMS: &[&str] = &[\n    \"verbose\",\n    \"debug\",\n    \"erroraction\",\n    \"errorvariable\",\n    \"informationaction\",\n    \"informationvariable\",\n    \"outvariable\",\n    \"outbuffer\",\n    \"pipelinevariable\",\n    \"warningaction\",\n    \"warningvariable\",\n    \"whatif\",","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/backend/parsers/windmill-parser-bash/src/lib.rs#L10-L46","documentation":"`parse_bash_sig` extracts a Bash script's signature by matching `VAR=\"$1\"`-style positional-argument assignments against RE_BASH. If no expected pattern matches (the parser cannot extract any parameters), it returns this generic error instead of a signature.","triggerScenarios":"Calling the Bash parser on a script whose parameters don't match `name=\"$1\"`, `name=\"${1}\"`, or `name=\"${1:-default}\"` — getopts/`read`-based args, `shift`/`$@` handling, `$1` used inline without a top-level assignment, or a script with no parseable arg lines.","commonSituations":"Scripts using getopts or long-option parsing libraries; positional args consumed inside expressions rather than via named assignment; scripts migrated from other shell tooling; authors expecting arbitrary bash arg parsing to be inferred.","solutions":["Rewrite parameter handling as top-level assignments of the form `param_name=\"$1\"`, `param_name=\"${1}\"`, or with a default `param_name=\"${1:-default}\"` — one per positional arg","Ensure each assignment matches the pattern exactly: `\\w+` name, value exactly `$N`, `${N}`, or `${N:-default}`, optionally with a trailing comment","Avoid getopts/shift-style parsing if you want Windmill to generate a UI signature from the script","If the script needs no typed params, define them via Windmill's script metadata/UI instead of relying on inference"],"exampleFix":"# before\nwhile getopts \"n:\" opt; do case $opt in n) name=$OPTARG;; esac; done\n# after\nname=\"${1:-world}\"","handlingStrategy":"validation","validationCode":"// quick local check that param lines are parseable before deploying\nconst ok = /^\\w+=\"\\$(?:\\d+|\\{\\d+\\}|\\{\\d+:-.*\\})\"(\\s*#.*)?$/m.test(code);","typeGuard":"function hasParseableBashParams(code) {\n  return /^\\w+=\"\\$(?:\\d+|\\{\\d+\\}|\\{\\d+:-[^}]*\\})\"/m.test(code);\n}","tryCatchPattern":"try { sig = parseBashSig(code); } catch (e) {\n  if (e.message === 'Error parsing bash script') {\n    // fall back to manually defined signature in script metadata\n  } else throw e;\n}","preventionTips":["Use the documented `var=\"$1\"` / `${1:-default}` idiom for every Bash script parameter","One positional arg per line, assigned to a named variable at top level","Don't consume positional args only inside functions or conditionals","Validate a new Bash script in the editor's signature preview before saving"],"tags":["bash","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"}