wagoodman/dive · error

directory for JSON export does not exist: %s

Error message

directory for JSON export does not exist: %s

What it means

Raised in Export.PostLoad() during option loading when a --json/-j path is given and os.Stat reports its parent directory does not exist. This is an early fail-fast check so the analysis (which can be slow) is never started for a destination that cannot be written.

Source

Thrown at cmd/dive/cli/internal/options/export.go:35

type Export struct {
	// Path to export analysis results as JSON (empty string = disabled)
	JsonPath string `yaml:"json-path" json:"json-path" mapstructure:"json-path"`
}

func DefaultExport() Export {
	return Export{}
}

func (o *Export) AddFlags(flags clio.FlagSet) {
	flags.StringVarP(&o.JsonPath, "json", "j", "Skip the interactive TUI and write the layer analysis statistics to a given file.")
}

func (o *Export) PostLoad() error {

	if o.JsonPath != "" {
		dir := path.Dir(o.JsonPath)
		if _, err := os.Stat(dir); os.IsNotExist(err) {
			return fmt.Errorf("directory for JSON export does not exist: %s", dir)
		}
	}

	return nil
}

View on GitHub (pinned to d6c691947f)

Solutions

  1. Create the directory first: mkdir -p $(dirname <path>) and rerun dive.
  2. Double-check the path string for typos and correct case on Linux.
  3. Write to an existing directory (e.g. the current dir) if creating dirs is not an option.
  4. In CI, add a 'mkdir -p artifacts' step before the dive step.

Example fix

# before
dive myimage --json reports/out.json  # reports/ missing

# after
mkdir -p reports && dive myimage --json reports/out.json
Defensive patterns

Strategy: validation

Validate before calling

dir := path.Dir(opts.Export.JsonPath)
if _, err := os.Stat(dir); os.IsNotExist(err) {
    if mkErr := os.MkdirAll(dir, 0o755); mkErr != nil {
        return fmt.Errorf("cannot create export dir: %w", mkErr)
    }
}

Prevention

When it happens

Trigger: Running dive with --json pointing into a directory that does not exist, e.g. --json reports/out.json when reports/ has not been created, or a typo in the path (misspelled or wrong-case directory on case-sensitive filesystems).

Common situations: CI scripts assuming an artifacts directory pre-exists; fresh clones without the output folder; Windows-style paths on Linux; trailing components stripped by shell expansion.

Related errors


AI-assisted analysis of wagoodman/dive@d6c691947f (2026-08-15). Data as JSON: /api/errors/6b3ad6029750f5f5. Report an issue: GitHub.