{"record":{"id":"b0db2aa74ae8ddef","repo":"gastownhall/beads","slug":"invalid-mode-s-must-be-compile-or-runtime","errorCode":null,"errorMessage":"invalid mode '%s', must be 'compile' or 'runtime'","messagePattern":"invalid mode '(.+?)', must be 'compile' or 'runtime'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/cook.go","lineNumber":133,"sourceCode":"\tforce, _ := cmd.Flags().GetBool(\"force\")\n\tsearchPaths, _ := cmd.Flags().GetStringSlice(\"search-path\")\n\tprefix, _ := cmd.Flags().GetString(\"prefix\")\n\tvarFlags, _ := cmd.Flags().GetStringArray(\"var\")\n\tmode, _ := cmd.Flags().GetString(\"mode\")\n\n\t// Parse variables\n\tinputVars := make(map[string]string)\n\tfor _, v := range varFlags {\n\t\tparts := strings.SplitN(v, \"=\", 2)\n\t\tif len(parts) != 2 {\n\t\t\treturn nil, fmt.Errorf(\"invalid variable format '%s', expected 'key=value'\", v)\n\t\t}\n\t\tinputVars[parts[0]] = parts[1]\n\t}\n\n\t// Validate mode\n\tif mode != \"\" && mode != \"compile\" && mode != \"runtime\" {\n\t\treturn nil, fmt.Errorf(\"invalid mode '%s', must be 'compile' or 'runtime'\", mode)\n\t}\n\n\t// Runtime mode is triggered by: explicit --mode=runtime OR providing --var flags\n\truntimeMode := mode == \"runtime\" || len(inputVars) > 0\n\n\treturn &cookFlags{\n\t\tdryRun:      dryRun,\n\t\tpersist:     persist,\n\t\tforce:       force,\n\t\tsearchPaths: searchPaths,\n\t\tprefix:      prefix,\n\t\tinputVars:   inputVars,\n\t\truntimeMode: runtimeMode,\n\t\tformulaPath: args[0],\n\t}, nil\n}\n\n// loadAndResolveFormula parses a formula file and applies all transformations.","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/cook.go#L115-L151","documentation":"parseCookFlags validates the --mode flag for `bd cook`. Only 'compile' and 'runtime' are accepted (empty string is allowed and means auto-select). Any other value produces this error listing the two valid choices. Runtime mode is also implicitly triggered by providing --var flags.","triggerScenarios":"Invoking `bd cook` with `--mode production`, `--mode run`, `--mode RUN`, or any value other than exactly compile/runtime/empty — the comparison is case-sensitive.","commonSituations":"Guessing mode names from other tools (prod/dev/run); capitalization slip (--mode Runtime); reusing a script that passed an unrelated tool's mode flag through to cook.","solutions":["Use --mode compile or --mode runtime (lowercase, exact)","Omit --mode entirely and let runtime mode auto-trigger from --var flags","Normalize the value in wrapper scripts, e.g. mode=$(echo \"$MODE\" | tr 'A-Z' 'a-z') and validate before calling bd"],"exampleFix":"// before\nbd cook formula --mode Runtime\n// after\nbd cook formula --mode runtime","handlingStrategy":"validation","validationCode":"// validate mode before invoking bd cook\nvar allowed = map[string]bool{\"\": true, \"compile\": true, \"runtime\": true}\nif !allowed[mode] {\n  return fmt.Errorf(\"invalid mode %q, must be 'compile' or 'runtime'\", mode)\n}","typeGuard":null,"tryCatchPattern":"if err := parseCookFlags(...); err != nil {\n  if strings.Contains(err.Error(), \"invalid mode\") {\n    // print usage: --mode compile|runtime\n  }\n  return err\n}","preventionTips":["Use only the exact lowercase values compile and runtime","Prefer omitting --mode; cook auto-selects runtime when --var flags are present","Whitelist/normalize the mode value in wrapper scripts before passing it through"],"tags":["cli","validation","mode","cook","enum-value"],"backgroundTag":"invalid-enum-value","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}