hashicorp/nomad · error

Unable to determine format of %s; Use the -in flag to specif

Error message

Unable to determine format of %s; Use the -in flag to specify it.

What it means

When a `@file` argument is given without an explicit `-in` flag, setParserForFileArg infers the input format from the file extension: .json and .hcl are recognized; anything else returns `Unable to determine format of %s; Use the -in flag to specify it.` The library supports only json and hcl as input formats.

Source

Thrown at command/var_put.go:585

	builder := &KVBuilder{Stdin: stdin}
	if err := builder.Add(args...); err != nil {
		return nil, err
	}
	return builder.Map(), nil
}

func (c *VarPutCommand) GetConcurrentUI() cli.ConcurrentUi {
	return cli.ConcurrentUi{Ui: c.Ui}
}

func (c *VarPutCommand) setParserForFileArg(arg string) error {
	switch filepath.Ext(arg) {
	case ".json":
		c.inFmt = "json"
	case ".hcl":
		c.inFmt = "hcl"
	default:
		return fmt.Errorf("Unable to determine format of %s; Use the -in flag to specify it.", arg)
	}
	return nil
}

func (c *VarPutCommand) validateInputFlag() error {
	switch c.inFmt {
	case "hcl", "json":
		return nil
	default:
		return errors.New(errInvalidInFormat)
	}
}

func (c *VarPutCommand) validateOutputFlag() error {
	if c.outFmt != "go-template" && c.tmpl != "" {
		return errors.New(errUnexpectedTemplate)
	}
	switch c.outFmt {

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Add the explicit flag: `nomad var put -in=json @spec.txt` (or `-in=hcl` as appropriate).
  2. Rename the file to end in .json or .hcl so inference works.
  3. Convert unsupported formats (YAML/TOML) to JSON or HCL first.

Example fix

// before
nomad var put -path app/config @spec.yml
// after
yq -o=json spec.yml > spec.json && nomad var put -path app/config @spec.json
Defensive patterns

Strategy: validation

Validate before calling

ext="${SPEC_FILE##*.}"
case "$ext" in
  json|hcl) ;;
  *) echo "unknown extension .$ext; pass -in=json or -in=hcl" >&2; exit 2 ;;
esac

Try / catch

if err := run(); err != nil && strings.Contains(err.Error(), "Unable to determine format of") {
    log.Fatal("pass -in=json or -in=hcl explicitly for this file")
}

Prevention

When it happens

Trigger: `nomad var put @spec.txt`, `@spec.yml`, or an extension-less file, without passing `-in`; also case-mismatched extensions like `@SPEC.JSON` on case-sensitive filesystems that the code still fails to recognize.

Common situations: Renaming spec files to .yaml/.yml assuming YAML support; downloaded files without extensions; generated temp files with random suffixes.

Related errors


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