docker/cli · error

cannot supply extra formatting options to the pretty…

Error message

cannot supply extra formatting options to the pretty template

What it means

The `docker secret inspect` command offers a built-in "pretty" template for human-readable output (set via the `--pretty` flag or `--format pretty`). This error fires at secret/inspect.go:58-59 when the resolved format string starts with "pretty" but is not exactly "pretty", meaning the user attempted to append Go template directives to the predefined pretty template (e.g., `--format "pretty {{.ID}}"`). The pretty format is a fixed, opaque template and cannot be combined with custom Go template expressions.

Solutions

  1. Use `--pretty` alone (no --format) for the built-in human-friendly output
  2. Use `--format` with a complete Go template from scratch (e.g., `--format "{{json .}}"`), omitting the "pretty" prefix
  3. Use `--format pretty` (exactly the word "pretty" with no trailing characters) as an alternative to --pretty

Example fix

# before
docker secret inspect --format "pretty {{.ID}}" mysecret

# after (option A: built-in pretty)
docker secret inspect --pretty mysecret

# after (option B: custom Go template)
docker secret inspect --format "{{json .}}" mysecret
Defensive patterns

Strategy: validation

Validate before calling

// Validate before calling runSecretInspect
func validateSecretFormat(format string, pretty bool) error {
    effective := format
    if pretty {
        effective = "pretty"
    }
    if strings.HasPrefix(effective, "pretty") && effective != "pretty" {
        return fmt.Errorf("format %q is invalid: use 'pretty' exactly or a full Go template", effective)
    }
    return nil
}

Prevention

When it happens

Trigger: Running `docker secret inspect --format "pretty {{.ID}}" mysecret` or any invocation where `opts.format` is set to a string with the prefix "pretty" followed by additional characters. Note: using `--pretty` alone is safe because line 48 sets `opts.format` to exactly `"pretty"`, which passes the check.

Common situations: A developer assumes "pretty" is a composable base template and tries to add fields to it, e.g., `--format "pretty some-extra"`. Or a wrapper script constructs a format string by concatenating "pretty" with template fragments.

Related errors


AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07). Data as JSON: /api/errors/1d6696bec77e3bbc. Report an issue: GitHub.

Appendix: source

Thrown at cli/command/secret/inspect.go:59

	return cmd
}

func runSecretInspect(ctx context.Context, dockerCLI command.Cli, opts inspectOptions) error {
	apiClient := dockerCLI.Client()

	if opts.pretty {
		opts.format = "pretty"
	}

	getRef := func(id string) (any, []byte, error) {
		res, err := apiClient.SecretInspect(ctx, id, client.SecretInspectOptions{})
		return res.Secret, res.Raw, err
	}

	// check if the user is trying to apply a template to the pretty format, which
	// is not supported
	if strings.HasPrefix(opts.format, "pretty") && opts.format != "pretty" {
		return errors.New("cannot supply extra formatting options to the pretty template")
	}

	secretCtx := formatter.Context{
		Output: dockerCLI.Out(),
		Format: newFormat(opts.format, false),
	}

	if err := inspectFormatWrite(secretCtx, opts.names, getRef); err != nil {
		return cli.StatusError{StatusCode: 1, Status: err.Error()}
	}
	return nil
}

View on GitHub (pinned to 4f84911bfe)