{"record":{"id":"355216985706f18a","repo":"tsenart/vegeta","slug":"error-reading-s-s","errorCode":null,"errorMessage":"error reading %s: %s","messagePattern":"error reading (.+?): (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"attack.go","lineNumber":148,"sourceCode":"\tnet.DefaultResolver.PreferGo = true\n\n\tfiles := map[string]io.Reader{}\n\tfor _, filename := range []string{opts.targetsf, opts.bodyf} {\n\t\tif filename == \"\" {\n\t\t\tcontinue\n\t\t}\n\t\tf, err := file(filename, false)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error opening %s: %s\", filename, err)\n\t\t}\n\t\tdefer f.Close()\n\t\tfiles[filename] = f\n\t}\n\n\tvar body []byte\n\tif bodyf, ok := files[opts.bodyf]; ok {\n\t\tif body, err = io.ReadAll(bodyf); err != nil {\n\t\t\treturn fmt.Errorf(\"error reading %s: %s\", opts.bodyf, err)\n\t\t}\n\t}\n\n\tvar (\n\t\ttr       vegeta.Targeter\n\t\tsrc      = files[opts.targetsf]\n\t\thdr      = opts.headers.Header\n\t\tproxyHdr = opts.proxyHeaders.Header\n\t)\n\n\tswitch opts.format {\n\tcase vegeta.JSONTargetFormat:\n\t\ttr = vegeta.NewJSONTargeter(src, body, hdr)\n\tcase vegeta.HTTPTargetFormat:\n\t\ttr = vegeta.NewHTTPTargeter(src, body, hdr)\n\tdefault:\n\t\treturn fmt.Errorf(\"format %q isn't one of [%s]\",\n\t\t\topts.format, strings.Join(vegeta.TargetFormats, \", \"))","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/tsenart/vegeta/blob/cf5811269046c672a604b1eb352204d30f16ae4a/attack.go#L130-L166","documentation":"After successfully opening the body file, attack() reads it fully with io.ReadAll; if reading fails (I/O error rather than open error) the filename and underlying error are wrapped. This indicates the file exists but its contents could not be read.","triggerScenarios":"`-body` file that becomes unreadable mid-read, a special/character device or FIFO that errors during read, or hardware/permission errors surfacing during ReadAll.","commonSituations":"Body file on a flaky network mount; passing a device path like /dev/stdin in an environment where stdin cannot be read; disk I/O errors.","solutions":["Check the wrapped underlying error for the real cause (I/O error, permission, etc.).","Copy the body to a regular local file and pass that path instead of a device/mounted path.","Re-run with a smaller/known-good body file to isolate the failing input."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if b, err := os.ReadFile(bodyPath); err != nil {\n    return fmt.Errorf(\"body file unreadable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if _, err := os.ReadFile(bodyPath); err != nil {\n    log.Fatalf(\"pre-check read of body %s failed: %v\", bodyPath, err)\n}","preventionTips":["Keep body files on local, reliable storage rather than network mounts or device nodes.","Pre-read the body file in a health check before long-running attacks.","Avoid passing special files (FIFOs, /dev entries) as -body."],"tags":["cli","filesystem","io"],"backgroundTag":"file-read-error","analyzedSha":"cf5811269046c672a604b1eb352204d30f16ae4a","analyzedAt":"2026-08-31T11:04:20.464Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}