hashicorp/nomad · error

format flag required

Error message

format flag required

What it means

VarPutCommand.makeVariable requires the -format flag (hcl or json) to know how to parse the variable contents. When no format was supplied (empty string), it returns this error before parsing anything.

Solutions

  1. Add -in=hcl or -in=json (matching your input contents) to the command
  2. If using a spec file, ensure the format flag is still provided
  3. Check the command help for the exact flag name in your version

Example fix

// before
vault kv put secret/foo @spec.hcl
// after
vault kv put -in=hcl secret/foo @spec.hcl
Defensive patterns

Strategy: validation

Validate before calling

if inFmt == "" {
	return errors.New("-in (hcl|json) is required when supplying contents to kv put")
}
if inFmt != "hcl" && inFmt != "json" {
	return fmt.Errorf("invalid -in %q", inFmt)
}

Try / catch

_, err := cmd.makeVariable()
if err != nil {
	if err.Error() == "format flag required" {
		// re-invoke with -in=hcl or -in=json
	}
	return err
}

Prevention

When it happens

Trigger: Running `vault kv put` (var put) with data/contents but without -in/-format, so c.format (inFmt) is "" when makeVariable switches on it.

Common situations: Piping a file via stdin without specifying -in=hcl or -in=json; upgrading from a workflow where format defaulted implicitly; scripts missing the flag after refactor.

Understand the failure class

Background: "--flag is required" and "must specify" CLI errors: how missing-required-flag validation works and how to fix it — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at command/var_put.go:431

		out.Path = path
		out.Namespace = c.Meta.namespace
		out.Items = make(map[string]string)
		return out, nil
	}

	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 {

View on GitHub (pinned to 482b49bf1a)