hashicorp/nomad · error

unknown format flag value

Error message

unknown format flag value

What it means

makeVariable validates the `-in` format flag with a switch over json/hcl/empty. Any value other than those (a mistyped format string) falls into the default branch and yields `unknown format flag value`. Note this message carries no wrapped detail, so it indicates purely an unsupported flag value.

Source

Thrown at command/var_put.go:436

	switch c.inFmt {
	case "json":
		err = json.Unmarshal(c.contents, out)
		if err != nil {
			return nil, fmt.Errorf("error unmarshaling json: %w", err)
		}
	case "hcl":
		out, err = parseVariableSpec(c.contents, c.verbose)
		if err != nil {
			return nil, fmt.Errorf("error parsing hcl: %w", err)
		}
	case "":
		return nil, errors.New("format flag required")
	default:
		return nil, fmt.Errorf("unknown format flag value")
	}

	// It is possible a specification file was used which did not declare any
	// items. Therefore, default the entry to avoid panics and ensure this type
	// of use is valid.
	if out.Items == nil {
		out.Items = make(map[string]string)
	}

	// Handle cases where values are provided by CLI flags that modify the
	// the created variable. Typical of a "copy" operation, it is a convenience
	// to reset the Create and Modify metadata to zero.
	var resetIndex bool

	// Step on the namespace in the object if one is provided by flag
	if c.Meta.namespace != "" && c.Meta.namespace != out.Namespace {
		out.Namespace = c.Meta.namespace
		resetIndex = true
	}

	// Step on the path in the object if one is provided by argument.

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Use exactly `-in=json` or `-in=hcl` (lowercase).
  2. Convert YAML/TOML specs to JSON or HCL before passing them to nomad.
  3. Check the templated/CI variable that supplies the format value for stray whitespace or case issues.

Example fix

// before
nomad var put -in=yaml @spec.yaml
// after
yq -o=json spec.yaml > spec.json && nomad var put -in=json @spec.json
Defensive patterns

Strategy: validation

Validate before calling

case "${IN_FMT:-}" in
  json|hcl|"") ;;
  *) echo "-in must be json or hcl, got: ${IN_FMT}" >&2; exit 2 ;;
esac

Try / catch

if err := run(); err != nil && err.Error() == "unknown format flag value" {
    log.Fatal("-in must be exactly 'json' or 'hcl' (lowercase)")
}

Prevention

When it happens

Trigger: `nomad var put -in=yaml @file`, `-in=JSON` (wrong case or an unsupported spelling), or scripts templating a format variable that contains an invalid value.

Common situations: Assuming YAML or TOML input is supported (only json and hcl are); uppercase format values in CI config; typos like `-in=jason`.

Understand the failure class

Background: "unknown output mode", "invalid value for flag", "expects true/false": fixing invalid flag value errors in CLI tools — this error's family across 24 libraries.

Related errors


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