{"record":{"id":"653500561853348a","repo":"windmill-labs/windmill","slug":"internal-error-cannot-check-if-argument-is-option","errorCode":null,"errorMessage":"Internal error, cannot check if argument is optional","messagePattern":"Internal error, cannot check if argument is optional","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/parsers/windmill-parser-nu/src/lib.rs","lineNumber":129,"sourceCode":"                        Some(parse_default(\n                            &batch\n                                .get(d..)\n                                .ok_or(anyhow!(\"Cannot parse default value of argument\"))?,\n                            &batches,\n                            i,\n                            &mut compensate_lookahead,\n                        )?),\n                    )\n                } else {\n                    bail!(\"Parsing error `:` should be before `=`\\nit likely means you are trying to set default value to record or table which is not supported at the moment.\")\n                }\n            }\n        };\n\n        // Check if it is optional\n        let optional = {\n            let Some(element) = name.chars().last() else {\n                bail!(\"Internal error, cannot check if argument is optional\")\n            };\n            element == '?'\n        };\n\n        // Rest parameters are not supported\n        if matches!(name.get(0..3), Some(\"...\")) {\n            bail!(\"Rest (...) parameters are not supported\")\n        }\n\n        // Flags are not supported\n        if matches!(name.get(0..2), Some(\"--\")) {\n            bail!(\"Flags are not supported\")\n        }\n\n        sig.args.push(Arg {\n            name: if optional {\n                name.get(..name.len() - 1).unwrap_or(\"Error\").to_owned()\n            } else {","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/backend/parsers/windmill-parser-nu/src/lib.rs#L111-L147","documentation":"After parsing a parameter's name, type and default, the parser checks whether the name ends with `?` to mark it optional. This fires when the extracted name string is empty so there is no last character to inspect — an internal invariant violation indicating the argument text produced an empty identifier. It signals malformed input that slipped past earlier `get`-based extraction (which used `unwrap_or(\"Error\")`-style fallbacks elsewhere, but here yields an empty string).","triggerScenarios":"A parameter batch in `def main [...]` that trims to an empty string yet reaches the optional check — e.g. degenerate argument lists like `def main [,]` or inputs where splitting on commas produces an empty segment not filtered out and name extraction yields \"\".","commonSituations":"Hand-edited parameter lists with stray/empty segments or only whitespace between commas; scripts generated by tooling that emits empty args.","solutions":["Fix the parameter list so each comma-separated segment is a valid identifier: `def main [a: int, b?: string]`.","Remove trailing/leading or doubled commas in the `def main [...]` signature.","Check for invisible characters (zero-width spaces) that break identifier extraction; retype the signature plainly.","If a valid-looking signature triggers it, report the script — it points to a parser edge case."],"exampleFix":"// before\ndef main [a: int, , b: string]\n// after\ndef main [a: int, b: string]","handlingStrategy":"validation","validationCode":"function validateNuParamList(sigText) {\n  const inner = sigText.match(/def\\s+main\\s*\\[([^\\]]*)\\]/)?.[1] ?? '';\n  const parts = inner.split(',').map(s => s.trim()).filter(Boolean);\n  const bad = parts.find(p => !/^[\\w-]+\\??(\\s*:.*)?(\\s*=.*)?$/.test(p));\n  return bad ? `invalid parameter segment: '${bad}' — each comma-separated param must be a non-empty identifier` : null;\n}","typeGuard":null,"tryCatchPattern":"try {\n  const sig = parseNuSignature(source);\n} catch (e) {\n  if (String(e).includes('cannot check if argument is optional')) {\n    throw new Error('Malformed parameter list in def main: remove empty/duplicate comma segments and invisible characters');\n  }\n  throw e;\n}","preventionTips":["Never leave empty segments between commas in the parameter list","Retype signatures manually after copy-paste to eliminate zero-width/invisible characters","Lint signatures with a regex for `ident[?][: type][= default]` shape before deploying"],"tags":["nushell","parser","internal-error","empty-identifier"],"backgroundTag":"parser-internal-invariant","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}