{"record":{"id":"03acc8a63808608e","repo":"vitessio/vitess","slug":"failed-to-load-flag-for-s-w","errorCode":null,"errorMessage":"failed to load flag for %s: %w","messagePattern":"failed to load flag for (.+?): %w","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/viperutil/internal/value/value.go","lineNumber":106,"sourceCode":"\tfor _, alias := range val.Aliases {\n\t\tv.RegisterAlias(alias, val.Key())\n\t}\n\n\tif len(val.EnvVars) > 0 {\n\t\tvars := append([]string{val.Key()}, val.EnvVars...)\n\t\t_ = v.BindEnv(vars...)\n\t}\n}\n\n// BindFlags creates bindings between each value's registry and the given flag\n// set. This function will panic if any of the values defines a flag that does\n// not exist in the flag set.\nfunc BindFlags(fs *pflag.FlagSet, values ...Registerable) {\n\tfor _, val := range values {\n\t\tflag, err := val.Flag(fs)\n\t\tswitch {\n\t\tcase err != nil:\n\t\t\tpanic(fmt.Errorf(\"failed to load flag for %s: %w\", val.Key(), err))\n\t\tcase flag == nil:\n\t\t\tcontinue\n\t\t}\n\n\t\t_ = val.Registry().BindPFlag(val.Key(), flag)\n\t\tif flag.Name != val.Key() {\n\t\t\tval.Registry().RegisterAlias(flag.Name, val.Key())\n\t\t}\n\t}\n}\n\n// Static is a static value. Static values register to the Static registry, and\n// do not respond to changes to config files. Their Get() method will return the\n// same value for the lifetime of the process.\ntype Static[T any] struct {\n\t*Base[T]\n}\n","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/viperutil/internal/value/value.go#L88-L124","documentation":"BindFlags in go/viperutil/internal/value wraps any error returned by val.Flag(fs) into \"failed to load flag for <key>\" and panics. Because flag registration happens at startup wiring time, a failure here is considered unrecoverable programmer error: a Registerable value could not produce its pflag definition for the given flag set.","triggerScenarios":"Calling viperutil.BindFlags(fs, vals...) where a Registerable's Flag() method returns a non-nil error — e.g. duplicate flag name already registered on fs, invalid flag name characters, or a value type whose flag factory fails.","commonSituations":"Registering the same flag key twice in one FlagSet (\"flag redefined\"); building a custom binary that binds both plugin-defined and built-in flags that collide; passing flags registered on multiple different FlagSets to a single BindFlags call.","solutions":["Read the wrapped inner error in the panic message — it names the underlying pflag failure; fix that first.","Ensure each Registerable is bound exactly once per FlagSet; remove duplicate BindFlags calls for the same key.","Verify no two registered values share the same Key(); rename one of the flags.","Confirm you pass the same *pflag.FlagSet that the value was designed to register into."],"exampleFix":"// before\nfs := pflag.NewFlagSet(\"cmd\", pflag.ContinueOnError)\nviperutil.BindFlags(fs, val1)\nviperutil.BindFlags(fs, val1) // panics: flag redefined\n// after\nviperutil.BindFlags(fs, val1)","handlingStrategy":"validation","validationCode":"seen := map[string]bool{}\nfor _, v := range values {\n\tif seen[v.Key()] {\n\t\tpanic(fmt.Sprintf(\"duplicate flag key %q passed to BindFlags\", v.Key()))\n\t}\n\tseen[v.Key()] = true\n}","typeGuard":null,"tryCatchPattern":"// BindFlags panics; wrap at binary startup\nfunc mustBindFlags(fs *pflag.FlagSet, vals ...viperutil.Registerable) {\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\tlog.Error(\"flag binding failed\", slog.Any(\"panic\", r))\n\t\t\tos.Exit(1)\n\t\t}\n\t}()\n\tviperutil.BindFlags(fs, vals...)\n}","preventionTips":["Bind each Registerable exactly once per FlagSet.","Keep flag keys unique per binary; prefix plugin flags.","Smoke-test binary startup (with --help) in CI so binding panics surface before deploy."],"tags":["flags","startup","panic"],"backgroundTag":"flag-binding-failed","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}