larksuite/cli · error

Hooks.NewArgs panicked

Error message

Hooks.NewArgs panicked: %v

What it means

probeNewArgs recovered a panic out of the author-supplied Hooks.NewArgs constructor - the definition's args factory is buggy; the recovered value is formatted into this error instead of crashing mount.

Solutions

  1. Fix NewArgs so it constructs the Args value without panicking (nil maps, bad receivers, etc.)
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at shortcuts/common/typed_external.go:69 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04). Data as JSON: /api/errors/c0f8ab8c95ac82fb. Report an issue: GitHub.

Appendix: source

Thrown at shortcuts/common/typed_external.go:69

	}
	if err := validateExternalFlagNamespace(compiled); err != nil {
		return Shortcut{}, err
	}
	shortcut := shortcutFromCompiled(compiled)
	if definition.PageOutput {
		shortcut.Flags = append(shortcut.Flags, PageAllFlags()...)
	}
	if err := validateTypedFlagMountPlan(compiled, shortcut.PrintFlagSchema != nil, typedRisk(shortcut.Risk)); err != nil {
		return Shortcut{}, err
	}
	return shortcut, nil
}

func probeNewArgs(newArgs func() any) (result any, err error) {
	defer func() {
		if recovered := recover(); recovered != nil {
			result = nil
			err = fmt.Errorf("Hooks.NewArgs panicked: %v", recovered)
		}
	}()
	return newArgs(), nil
}

func adaptBridgeHooks(hooks commandbridge.Hooks) compiledHooks {
	adapted := compiledHooks{
		newArgs:   hooks.NewArgs,
		normalize: hooks.Normalize,
		validate:  hooks.Validate,
		renderers: hooks.Renderers,
	}
	if hooks.DryRun != nil {
		adapted.dryRun = func(ctx context.Context, runtime typedRuntimeContext, args any) (*DryRunAPI, error) {
			value, err := hooks.DryRun(ctx, runtime, args)
			if err != nil || value == nil {
				return nil, err
			}

View on GitHub (pinned to 7fd6ef3c07)