{"record":{"id":"8f35d27fc582a35d","repo":"larksuite/cli","slug":"bind-flag-aliases-command-is-nil","errorCode":null,"errorMessage":"bind flag aliases: command is nil","messagePattern":"bind flag aliases: command is nil","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/flagalias/flagalias.go","lineNumber":50,"sourceCode":"\tAliases   []string\n}\n\n// Bind installs exact-name aliases on cmd and records them on their canonical\n// pflags for manifest/tooling introspection. Existing pflag normalization is\n// composed first; alias resolution is then applied to the normalized spelling.\n// The canonical pflag also remembers the spelling that supplied its most\n// recently applied value so validation errors can point back to the caller's\n// actual input without changing native repeated-flag semantics.\n//\n// Bind is intentionally the only production owner of SetNormalizeFunc. It\n// validates the complete accepted-name set before installing alias metadata or\n// a normalizer, so a configuration error cannot leave aliases partially bound.\nfunc Bind(cmd *cobra.Command, specs []Spec) error {\n\tif len(specs) == 0 {\n\t\treturn nil\n\t}\n\tif cmd == nil {\n\t\treturn fmt.Errorf(\"bind flag aliases: command is nil\")\n\t}\n\n\tcmd.InitDefaultHelpFlag()\n\tflagSet := cmd.Flags()\n\tprevious := flagSet.GetNormalizeFunc()\n\tnormalize := func(name string) string {\n\t\tif previous == nil {\n\t\t\treturn name\n\t\t}\n\t\treturn string(previous(flagSet, name))\n\t}\n\n\tregistered := make(map[string]string)\n\tcollectRegistered(registered, flagSet)\n\tcollectRegistered(registered, cmd.InheritedFlags())\n\n\t// Existing annotations matter when Bind is composed by multiple adapters:\n\t// aliases are not independent pflags, so VisitAll alone cannot see them.","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/flagalias/flagalias.go#L32-L68","documentation":"Programmer-error guard in Bind: invoked with a nil cobra command. Flag alias binding requires a live command to look up flag sets and command paths; there is no recovery path other than passing a valid command.","triggerScenarios":"Thrown at internal/flagalias/flagalias.go:50 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Construct the cobra command before calling Bind","Audit MustBind call sites for nil-unsafe initialization order"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}