{"record":{"id":"ae417d8701b2426c","repo":"larksuite/cli","slug":"postmount-removed-typed-flag-s","errorCode":null,"errorMessage":"PostMount removed Typed flag --%s","messagePattern":"PostMount removed Typed flag --(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/common/typed_mount_guard.go","lineNumber":97,"sourceCode":"\tseen := make(map[string]struct{}, len(before.flags)+len(after.flags))\n\tfor name := range before.flags {\n\t\tseen[name] = struct{}{}\n\t\tnames = append(names, name)\n\t}\n\tfor name := range after.flags {\n\t\tif _, ok := seen[name]; !ok {\n\t\t\tnames = append(names, name)\n\t\t}\n\t}\n\tsort.Strings(names)\n\tfor _, name := range names {\n\t\tbeforeFlag, existedBefore := before.flags[name]\n\t\tafterFlag, existsAfter := after.flags[name]\n\t\tswitch {\n\t\tcase !existedBefore:\n\t\t\treturn fmt.Errorf(\"PostMount added undeclared Typed flag --%s\", name)\n\t\tcase !existsAfter:\n\t\t\treturn fmt.Errorf(\"PostMount removed Typed flag --%s\", name)\n\t\tcase !reflect.DeepEqual(beforeFlag, afterFlag):\n\t\t\treturn fmt.Errorf(\"PostMount modified Typed flag --%s or its input annotations\", name)\n\t\t}\n\t}\n\treturn nil\n}\n","sourceCodeStart":79,"sourceCodeEnd":104,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/common/typed_mount_guard.go#L79-L104","documentation":"This is a registration-time programmer diagnostic thrown by validateTypedPostMount. After a shortcut's PostMount hook runs, the guard re-snapshots the cobra command and compares it against a snapshot taken before mounting; if a flag that was declared during mount no longer exists, it means PostMount deleted a Typed-declared flag, which would silently change the command's contract. It is raised inside mountDeclarative's panic boundary, not at command execution time.","triggerScenarios":"A PostMount hook implementation calls Flags() combined with flag set manipulation that removes a previously declared flag, e.g. cobra's LocalFlags().MarkHidden misuse combined with deletion, an explicit FlagSet deletion, or re-registering flags on the wrong command so a declared flag disappears from LocalFlags.","commonSituations":"Developers adding custom PostMount hooks to shortcuts, refactoring shared flag setup into helpers that accidentally call ResetFlags(), or porting an older cobra pattern where flags were conditionally removed after definition.","solutions":["Inspect the PostMount hook in your shortcut and remove any code that deletes flags (flag set reset/deletion, replacing command.Flags()).","If the flag should genuinely not exist, remove its Typed declaration from the mount input instead of deleting it in PostMount.","If a shared helper mutates flags, scope it so it only adds flags declared in the Typed definition, never removes them."],"exampleFix":"// before (PostMount hook)\nfunc (h *hook) PostMount(cmd *cobra.Command) error {\n    cmd.Flags().ResetFlags() // wipes declared Typed flags\n    return nil\n}\n// after\nfunc (h *hook) PostMount(cmd *cobra.Command) error {\n    // only annotate or adjust existing declared flags; do not remove them\n    _ = cmd.Flags().SetAnnotation(\"user_id\", \"example\", []string{\"ou_xxx\"})\n    return nil\n}","handlingStrategy":"validation","validationCode":"// In tests for a custom PostMount hook, mount the shortcut and assert the declared flag set is intact:\nbefore := map[string]bool{\"user_id\": true, \"chat_id\": true}\nfor name := range before {\n    if cmd.Flags().Lookup(name) == nil {\n        t.Errorf(\"flag --%s was removed by PostMount\", name)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat PostMount as read-only regarding flags: only annotate or adjust, never add/remove/modify declared flags.","Keep flag metadata (usage, hidden, shorthand, defaults) in the Typed declaration, not in hooks.","Add a shortcut mount test that runs in dry-run mode so the guard panic surfaces in CI."],"tags":["cli","flags","registration","postmount","guard"],"backgroundTag":"postmount-flag-mutation-forbidden","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"}