{"record":{"id":"6b3ad6029750f5f5","repo":"wagoodman/dive","slug":"directory-for-json-export-does-not-exist-s","errorCode":null,"errorMessage":"directory for JSON export does not exist: %s","messagePattern":"directory for JSON export does not exist: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/dive/cli/internal/options/export.go","lineNumber":35,"sourceCode":"type Export struct {\n\t// Path to export analysis results as JSON (empty string = disabled)\n\tJsonPath string `yaml:\"json-path\" json:\"json-path\" mapstructure:\"json-path\"`\n}\n\nfunc DefaultExport() Export {\n\treturn Export{}\n}\n\nfunc (o *Export) AddFlags(flags clio.FlagSet) {\n\tflags.StringVarP(&o.JsonPath, \"json\", \"j\", \"Skip the interactive TUI and write the layer analysis statistics to a given file.\")\n}\n\nfunc (o *Export) PostLoad() error {\n\n\tif o.JsonPath != \"\" {\n\t\tdir := path.Dir(o.JsonPath)\n\t\tif _, err := os.Stat(dir); os.IsNotExist(err) {\n\t\t\treturn fmt.Errorf(\"directory for JSON export does not exist: %s\", dir)\n\t\t}\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":17,"sourceCodeEnd":41,"githubUrl":"https://github.com/wagoodman/dive/blob/d6c691947f8fda635c952a17ee3b7555379d58f0/cmd/dive/cli/internal/options/export.go#L17-L41","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Create the directory first: mkdir -p $(dirname <path>) and rerun dive.","Double-check the path string for typos and correct case on Linux.","Write to an existing directory (e.g. the current dir) if creating dirs is not an option.","In CI, add a 'mkdir -p artifacts' step before the dive step."],"exampleFix":"# before\ndive myimage --json reports/out.json  # reports/ missing\n\n# after\nmkdir -p reports && dive myimage --json reports/out.json","handlingStrategy":"validation","validationCode":"dir := path.Dir(opts.Export.JsonPath)\nif _, err := os.Stat(dir); os.IsNotExist(err) {\n    if mkErr := os.MkdirAll(dir, 0o755); mkErr != nil {\n        return fmt.Errorf(\"cannot create export dir: %w\", mkErr)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always mkdir -p the output directory in CI before the dive step.","Use --json out/report.json relative to the working directory.","Fail fast on path typos by validating paths in the pipeline script."],"tags":["dive","export","json","filesystem","cli"],"backgroundTag":null,"analyzedSha":"d6c691947f8fda635c952a17ee3b7555379d58f0","analyzedAt":"2026-08-15T09:42:35.293Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}