{"record":{"id":"739c0247d2c6c9ff","repo":"sipeed/picoclaw","slug":"create-output-dir-w","errorCode":null,"errorMessage":"create output dir: %w","messagePattern":"create output dir: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/membench/eval.go","lineNumber":269,"sourceCode":"\t\tbyCat[cat] = cm\n\t}\n\tvar overallF1 float64\n\tif validF1Count > 0 {\n\t\toverallF1 = totalF1 / float64(validF1Count)\n\t}\n\treturn AggMetrics{\n\t\tOverallF1:      overallF1,\n\t\tOverallHitRate: totalHitRate / float64(nHit),\n\t\tByCategory:     byCat,\n\t\tTotalQuestions: len(qaResults),\n\t\tValidF1Count:   validF1Count,\n\t}\n}\n\n// SaveResults writes per-sample eval results to JSON files.\nfunc SaveResults(results []EvalResult, outDir string) error {\n\tif err := os.MkdirAll(outDir, 0o755); err != nil {\n\t\treturn fmt.Errorf(\"create output dir: %w\", err)\n\t}\n\tfor _, r := range results {\n\t\tpath := filepath.Join(outDir, fmt.Sprintf(\"eval_%s_%s.json\", r.Mode, r.SampleID))\n\t\tdata, err := json.MarshalIndent(r, \"\", \"  \")\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"marshal result: %w\", err)\n\t\t}\n\t\tif err := os.WriteFile(path, data, 0o644); err != nil {\n\t\t\treturn fmt.Errorf(\"write result: %w\", err)\n\t\t}\n\t}\n\treturn nil\n}\n\n// SaveAggregated writes a combined results.json with all modes.\nfunc SaveAggregated(results []EvalResult, outDir string) error {\n\tbyMode := map[string][]EvalResult{}\n\tfor _, r := range results {","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/sipeed/picoclaw/blob/49183d7e8daed0dba89ddbb6fcb60089401d9680/cmd/membench/eval.go#L251-L287","documentation":"Wrapped os.MkdirAll failure at the top of SaveResults in cmd/membench/eval.go. Before writing any per-sample JSON file, the eval harness creates outDir with mode 0755; if the directory cannot be created the error is wrapped with 'create output dir' and propagates, aborting the save phase (results computed so far are not persisted).","triggerScenarios":"outDir is inside a read-only mount or one owned by another user (EACCES/EPERM); a parent path component exists as a regular file (ENOTDIR); outDir points to a location like /proc or a full disk (ENOSPC); I/O errors on network storage.","commonSituations":"Running membench with -out /root/results as non-root; container with a read-only volume mounted at the output path; leftover file named like the output dir; NFS/sshfs hiccup mid-run.","solutions":["Point -out at a writable directory you own, e.g. $HOME/membench-results","Remove any regular file occupying the intended directory path, then rerun","Check with os.Stat/os.MkdirAll in a preflight or just mkdir -p the path manually before the run","Free space / fix mount permissions if the error is ENOSPC or EROFS"],"exampleFix":"// before\nif err := os.MkdirAll(outDir, 0o755); err != nil {\n    return fmt.Errorf(\"create output dir: %w\", err)\n}\n\n// after (preflight in main before the expensive eval runs)\nif err := os.MkdirAll(outDir, 0o755); err != nil {\n    return fmt.Errorf(\"output dir %s not writable: %w\", outDir, err)\n}","handlingStrategy":"validation","validationCode":"if err := os.MkdirAll(outDir, 0o755); err != nil {\n    return fmt.Errorf(\"output dir %s unusable: %w\", outDir, err)\n}\nif f, err := os.CreateTemp(outDir, \".writecheck-\"); err != nil {\n    return fmt.Errorf(\"output dir %s not writable: %w\", outDir, err)\n} else {\n    f.Close()\n    os.Remove(f.Name())\n}","typeGuard":null,"tryCatchPattern":"if err := eval.SaveResults(results, outDir); err != nil {\n    if errors.Is(err, fs.ErrPermission) || errors.Is(err, fs.ErrNotExist) {\n        // fall back to a temp dir so results are not lost after an expensive run\n        tmp := filepath.Join(os.TempDir(), \"membench-results\")\n        if err2 := eval.SaveResults(results, tmp); err2 == nil {\n            log.Printf(\"saved to fallback %s\", tmp)\n            return nil\n        }\n    }\n    return err\n}","preventionTips":["mkdir -p the output directory before starting the (expensive) eval run","Prefer $HOME-relative output paths in containers","Ensure no regular file shadows the directory name","Save partial results periodically instead of only at the end"],"tags":["go","filesystem","benchmark","permissions"],"backgroundTag":null,"analyzedSha":"49183d7e8daed0dba89ddbb6fcb60089401d9680","analyzedAt":"2026-08-15T21:55:41.315Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}