hashicorp/nomad · error

Unsupported format is specified.

Error message

Unsupported format is specified.

What it means

DataFormat returns this error when the format argument matches neither "json" nor "template" (the fallthrough at the end of the switch). The library only supports these two output formatters, so any other format string is unsupported.

Source

Thrown at command/data_format.go:39

// DataFormatter is a transformer of the data.
type DataFormatter interface {
	// TransformData should return transformed string data.
	TransformData(any) (string, error)
}

// DataFormat returns the data formatter specified format.
func DataFormat(format, tmpl string) (DataFormatter, error) {
	switch format {
	case "json":
		if len(tmpl) > 0 {
			return nil, fmt.Errorf("json format does not support template option.")
		}
		return &JSONFormat{}, nil
	case "template":
		return &TemplateFormat{tmpl}, nil
	}
	return nil, fmt.Errorf("Unsupported format is specified.")
}

type JSONFormat struct{}

// TransformData returns JSON format string data.
func (p *JSONFormat) TransformData(data any) (string, error) {
	var buf bytes.Buffer
	err := codec.NewEncoder(&buf, jsonHandlePretty).Encode(data)
	if err != nil {
		return "", err
	}

	return buf.String(), nil
}

type TemplateFormat struct {
	tmpl string
}

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Pass exactly "json" or "template" as the format value.
  2. Check the -format flag value for typos and case (values are lowercase, exact match).
  3. Ensure the format flag has a default set in your command wiring so it is never empty.
  4. If you need another output type, implement your own DataFormatter instead of extending DataFormat.

Example fix

// before
f, err := command.DataFormat("jso", "")
// after
f, err := command.DataFormat("json", "")
Defensive patterns

Strategy: validation

Validate before calling

var validFormats = map[string]bool{"json": true, "template": true}
if !validFormats[format] {
    return fmt.Errorf("format must be json or template, got %q", format)
}

Type guard

null

Try / catch

f, err := command.DataFormat(format, tmpl)
if err != nil {
    if strings.Contains(err.Error(), "Unsupported format") {
        f, err = command.DataFormat("json", "") // safe fallback
    }
}

Prevention

When it happens

Trigger: Calling command.DataFormat(format, tmpl) with format values like "", "text", "pretty", or a typo such as "jso" / "templete".

Common situations: Typo in the -format flag value; empty format because a flag was never set; copy-pasted format names from other tools (e.g. "yaml"); upstream code passing an uninitialized format variable.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/318548082217cc3a. Report an issue: GitHub.