hashicorp/packer · error

Error reading variables in '%s': %s

Error message

Error reading variables in '%s': %s

What it means

CLI error from the -var-file flag handler (FlagJSON.Set): the file was opened successfully but its contents could not be decoded as a JSON object of string variables. The wrapped %s is the encoding/json decode error pinpointing the bad JSON.

Source

Thrown at command/flag-kv/flag_json.go:32

type FlagJSON map[string]string

func (v *FlagJSON) String() string {
	return ""
}

func (v *FlagJSON) Set(raw string) error {
	f, err := os.Open(raw)
	if err != nil {
		return err
	}
	defer f.Close()

	if *v == nil {
		*v = make(map[string]string)
	}

	if err := json.NewDecoder(f).Decode(v); err != nil {
		return fmt.Errorf(
			"Error reading variables in '%s': %s", raw, err)
	}

	return nil
}

View on GitHub (pinned to eb36e3c3e4)

Solutions

  1. Validate the file with a JSON linter and fix syntax errors (trailing commas, missing quotes/braces)
  2. Ensure the top-level value is an object whose values are strings, e.g. {"image_id": "ami-123"}
  3. Use a .hcl variables file instead if you prefer HCL syntax
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at command/flag-kv/flag_json.go:32 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05). Data as JSON: /api/errors/dd31e242d6a91ebd. Report an issue: GitHub.