{"record":{"id":"dd6725c0eca20f5d","repo":"JuliusBrussee/caveman","slug":"export-directory-is-required","errorCode":null,"errorMessage":"export directory is required","messagePattern":"export directory is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/internal/store/report.go","lineNumber":116,"sourceCode":"\t\treturn fmt.Errorf(\"report path is required\")\n\t}\n\tif err := os.MkdirAll(filepath.Dir(outPath), 0o700); err != nil {\n\t\treturn err\n\t}\n\tf, err := os.OpenFile(outPath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0o600)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer f.Close()\n\treturn trialTemplate.Execute(f, struct {\n\t\tPlan      TrialPlan\n\t\tGenerated string\n\t}{Plan: plan, Generated: time.Now().UTC().Format(time.RFC3339)})\n}\n\nfunc (s *Store) ExportTrial(plan TrialPlan, outDir string) (map[string]string, error) {\n\tif outDir == \"\" {\n\t\treturn nil, fmt.Errorf(\"export directory is required\")\n\t}\n\tif err := os.MkdirAll(outDir, 0o700); err != nil {\n\t\treturn nil, err\n\t}\n\ttrialPath := filepath.Join(outDir, \"trial.json\")\n\traw, _ := json.MarshalIndent(plan, \"\", \"  \")\n\tif err := os.WriteFile(trialPath, append(raw, '\\n'), 0o600); err != nil {\n\t\treturn nil, err\n\t}\n\tspansPath := filepath.Join(outDir, \"spans.jsonl\")\n\tf, err := os.OpenFile(spansPath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0o600)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif err := s.writeExportSpans(f, plan); err != nil {\n\t\t_ = f.Close()\n\t\treturn nil, err\n\t}","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/proxy/internal/store/report.go#L98-L134","documentation":"ExportTrial writes the trial plan as JSON plus related artifacts into outDir. An empty outDir is rejected with 'export directory is required' before any directory is created, preventing writes to unintended locations. It is the directory-level analogue of the report-path guards.","triggerScenarios":"Calling ExportTrial (directly or via runTrial) with an empty outDir, e.g. when the export directory flag/env var was not provided.","commonSituations":"Automation omitting the export-dir flag for a trial run; an unset EXPORT_DIR env var; a wrapper script that strips empty arguments.","solutions":["Supply the export directory argument to the trial command","Set the environment variable or config field that carries outDir","Add a caller-side check that fails with a clear message when the directory is blank"],"exampleFix":"// before\nstore.ExportTrial(plan, os.Getenv(\"TRIAL_EXPORT_DIR\"))\n// after\ndir := os.Getenv(\"TRIAL_EXPORT_DIR\")\nif dir == \"\" {\n    return fmt.Errorf(\"TRIAL_EXPORT_DIR must point at an export directory\")\n}\nstore.ExportTrial(plan, dir)","handlingStrategy":"validation","validationCode":"if outDir == \"\" { return fmt.Errorf(\"trial export directory is required\") }\nif info, err := os.Stat(outDir); err == nil && !info.IsDir() { return fmt.Errorf(\"%s is not a directory\", outDir) }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set a default export directory in your automation","Fail fast when the export-dir env var is unset or empty","Validate the target is a directory (or creatable) before exporting","Document the export-dir flag as mandatory in usage text"],"tags":["cli","validation","export"],"backgroundTag":"empty-required-field","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}