larksuite/cli · error
PostMount removed Typed flag --%s
Error message
PostMount removed Typed flag --%s
What it means
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.
Source
Thrown at shortcuts/common/typed_mount_guard.go:97
seen := make(map[string]struct{}, len(before.flags)+len(after.flags))
for name := range before.flags {
seen[name] = struct{}{}
names = append(names, name)
}
for name := range after.flags {
if _, ok := seen[name]; !ok {
names = append(names, name)
}
}
sort.Strings(names)
for _, name := range names {
beforeFlag, existedBefore := before.flags[name]
afterFlag, existsAfter := after.flags[name]
switch {
case !existedBefore:
return fmt.Errorf("PostMount added undeclared Typed flag --%s", name)
case !existsAfter:
return fmt.Errorf("PostMount removed Typed flag --%s", name)
case !reflect.DeepEqual(beforeFlag, afterFlag):
return fmt.Errorf("PostMount modified Typed flag --%s or its input annotations", name)
}
}
return nil
}
View on GitHub (pinned to 7fd6ef3c07)
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.
Example fix
// before (PostMount hook)
func (h *hook) PostMount(cmd *cobra.Command) error {
cmd.Flags().ResetFlags() // wipes declared Typed flags
return nil
}
// after
func (h *hook) PostMount(cmd *cobra.Command) error {
// only annotate or adjust existing declared flags; do not remove them
_ = cmd.Flags().SetAnnotation("user_id", "example", []string{"ou_xxx"})
return nil
} Defensive patterns
Strategy: validation
Validate before calling
// In tests for a custom PostMount hook, mount the shortcut and assert the declared flag set is intact:
before := map[string]bool{"user_id": true, "chat_id": true}
for name := range before {
if cmd.Flags().Lookup(name) == nil {
t.Errorf("flag --%s was removed by PostMount", name)
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- PostMount modified Typed flag --%s or its input annotations
- name %q must not include leading dashes
- name %q must not contain whitespace
- name %q must not contain '='
- deprecated alias --%s must use independent mode so Cobra can
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/ae417d8701b2426c.
Report an issue: GitHub.