{"record":{"id":"a6614cbe0c9938d1","repo":"gastownhall/beads","slug":"errvarvalidation","errorCode":"ErrVarValidation","errorMessage":"%w:\n  - %s","messagePattern":"%w:\n  - (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/formula/parser.go","lineNumber":459,"sourceCode":"// ValidateVars checks that all required variables are provided\n// and all values pass their constraints.\nfunc ValidateVars(formula *Formula, values map[string]string) error {\n\tvar errs []string\n\n\tfor name, def := range formula.Vars {\n\t\tval, provided := values[name]\n\n\t\t// Check required\n\t\tif def.Required && !provided {\n\t\t\terrs = append(errs, fmt.Sprintf(\"variable %q is required\", name))\n\t\t\tcontinue\n\t\t}\n\n\t\terrs = append(errs, validateVarValue(name, def, val, provided)...)\n\t}\n\n\tif len(errs) > 0 {\n\t\treturn fmt.Errorf(\"%w:\\n  - %s\", ErrVarValidation, strings.Join(errs, \"\\n  - \"))\n\t}\n\n\treturn nil\n}\n\n// ValidateProvidedVars checks enum/pattern/required-empty constraints only\n// for variables that are present in values; it does not flag variables that\n// are entirely absent. Callers that already surface a more specific\n// missing-variable message (e.g. bd mol pour/wisp's hint path) should keep\n// using that path for absent vars — this exists so those same callers still\n// catch malformed *provided* values, which a presence-only check misses\n// (mybd-u2r6).\nfunc ValidateProvidedVars(formula *Formula, values map[string]string) error {\n\tvar errs []string\n\n\tfor name, def := range formula.Vars {\n\t\tval, provided := values[name]\n\t\tif !provided {","sourceCodeStart":441,"sourceCodeEnd":477,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/formula/parser.go#L441-L477","documentation":"ValidateVars() collected one or more per-variable failures from validateVarValue (missing required vars, enum violations, pattern mismatches) and returns them wrapped with the sentinel ErrVarValidation so callers can match with errors.Is. All failures are joined as a bulleted list after a single header line.","triggerScenarios":"Calling ValidateVars (directly or via formula execution paths) when provided var values violate constraints: a required var is absent, a value is not in the var's enum list, or a value does not match the var's pattern regex.","commonSituations":"CI invoking a formula without all required vars set in the environment or invocation flags; a var default was removed while callers still omit it; an enum value was renamed upstream; a pattern was tightened and previously-valid input now fails.","solutions":["Read each bullet in the error; supply every missing required var and correct enum/pattern violations in the invocation or defaults.","Match errors.Is(err, ErrVarValidation) in your tooling to print a friendly pre-flight message instead of a stack.","Update the formula's var defaults or loosen the enum/pattern if the constraint itself is outdated."],"exampleFix":"// before\nerr := f.ValidateVars(nil) // required vars missing\n\n// after\nvars := map[string]string{\"env\": \"prod\", \"region\": \"us-east-1\"}\nif err := f.ValidateVars(vars); err != nil {\n    if errors.Is(err, ErrVarValidation) { /* show bullets to user */ }\n}","handlingStrategy":"validation","validationCode":"// Pre-flight check required vars against their definitions before invoking.\nfor name, def := range f.Vars {\n\tif def.Required {\n\t\tif _, ok := provided[name]; !ok {\n\t\t\tfmt.Printf(\"missing required var: %s\\n\", name)\n\t\t}\n\t}\n}","typeGuard":null,"tryCatchPattern":"if err := f.ValidateVars(provided); err != nil {\n\tif errors.Is(err, ErrVarValidation) {\n\t\t// print err.Error() verbatim: it already lists each failure as a bullet\n\t}\n}","preventionTips":["Always call ValidateVars before executing a formula; treat ErrVarValidation as user input error, not a bug.","Keep var defaults in the formula so required vars are rarely absent.","When changing an enum or pattern, grep callers for the old accepted values."],"tags":["go","validation","variables","sentinel-error"],"backgroundTag":"schema-validation-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}