docker/cli · error · ErrHookTemplateParse

failed to parse hook template: arg: cmd is nil

Error message

failed to parse hook template: arg: cmd is nil

What it means

Error "failed to parse hook template: arg: cmd is nil" thrown in docker/cli.

Source

Thrown at cli-plugins/hooks/template.go:87

	return c.cmd.Name()
}

// flagValue returns the value that was set for the given flag when the hook was invoked.
func (c commandInfo) flagValue(flagName string) (string, error) {
	if c.cmd == nil {
		return "", fmt.Errorf("%w: flagValue: cmd is nil", ErrHookTemplateParse)
	}
	f := c.cmd.Flag(flagName)
	if f == nil {
		return "", fmt.Errorf("%w: flagValue: no flags found", ErrHookTemplateParse)
	}
	return f.Value.String(), nil
}

// argValue returns the value of the nth argument.
func (c commandInfo) argValue(n int) (string, error) {
	if c.cmd == nil {
		return "", fmt.Errorf("%w: arg: cmd is nil", ErrHookTemplateParse)
	}
	flags := c.cmd.Flags()
	v := flags.Arg(n)
	if v == "" && n >= flags.NArg() {
		return "", fmt.Errorf("%w: arg: %dth argument not set", ErrHookTemplateParse, n)
	}
	return v, nil
}

View on GitHub (pinned to e9452d6e78)

When it happens

Trigger: Thrown at cli-plugins/hooks/template.go:87 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of docker/cli@e9452d6e78 (2026-08-01). Data as JSON: /data/errors/729de5ec4f12dc85.json. Report an issue: GitHub.