{"record":{"id":"493903820d5d4123","repo":"tsenart/vegeta","slug":"bad-body-w","errorCode":null,"errorMessage":"bad body: %w","messagePattern":"bad body: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/targets.go","lineNumber":314,"sourceCode":"\t\t\treturn fmt.Errorf(\"bad method: %s\", tokens[0])\n\t\t}\n\t\ttgt.Method = tokens[0]\n\t\tif _, err = url.ParseRequestURI(tokens[1]); err != nil {\n\t\t\treturn fmt.Errorf(\"bad URL: %s, %w\", tokens[1], err)\n\t\t}\n\t\ttgt.URL = tokens[1]\n\t\tline = strings.TrimSpace(sc.Peek())\n\t\tif line == \"\" || startsWithHTTPMethod(line) {\n\t\t\treturn nil\n\t\t}\n\t\tfor sc.Scan() {\n\t\t\tif line = strings.TrimSpace(sc.Text()); line == \"\" {\n\t\t\t\tbreak\n\t\t\t} else if strings.HasPrefix(line, \"#\") {\n\t\t\t\tcontinue\n\t\t\t} else if strings.HasPrefix(line, \"@\") {\n\t\t\t\tif tgt.Body, err = os.ReadFile(line[1:]); err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"bad body: %w\", err)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\ttokens = strings.SplitN(line, \":\", 2)\n\t\t\tif len(tokens) < 2 {\n\t\t\t\treturn fmt.Errorf(\"bad header: %s\", line)\n\t\t\t}\n\t\t\tfor i := range tokens {\n\t\t\t\tif tokens[i] = strings.TrimSpace(tokens[i]); tokens[i] == \"\" {\n\t\t\t\t\treturn fmt.Errorf(\"bad header: %s\", line)\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add key/value directly to the http.Header (map[string][]string).\n\t\t\t// http.Header.Add() canonicalizes keys but vegeta is used\n\t\t\t// to test systems that require case-sensitive headers.\n\t\t\ttgt.Header[tokens[0]] = append(tgt.Header[tokens[0]], tokens[1])\n\t\t}\n\t\tif err = sc.Err(); err != nil {","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/tsenart/vegeta/blob/cf5811269046c672a604b1eb352204d30f16ae4a/lib/targets.go#L296-L332","documentation":"Returned when a target line's body directive (a line starting with '@') points to a file that cannot be read. The parser calls os.ReadFile on the path following '@' and wraps the error as \"bad body\".","triggerScenarios":"A targets file contains \"@/path/to/body.json\" where the file does not exist, lacks read permission, or the path is relative to the wrong working directory.","commonSituations":"Referencing a request body file with a relative path while running vegeta from another directory, forgetting to create the payload file, permission-restricted files in CI containers.","solutions":["Verify the file after '@' exists and is readable at that path (use an absolute path).","Run vegeta from the directory you expect, or make the @ path absolute.","Check file permissions for the vegeta process user.","Confirm the line really begins with '@' only when pointing at a body file; escape or fix accidental '@' usages."],"exampleFix":"// before\nPOST http://api/\n@data/payload.json\n// after (from repo root)\nPOST http://api/\n@/abs/path/data/payload.json","handlingStrategy":"validation","validationCode":"func validateBodyRef(line string) error {\n    if !strings.HasPrefix(line, \"@\") { return nil }\n    path := strings.TrimSpace(line[1:])\n    if path == \"\" { return fmt.Errorf(\"empty body path\") }\n    f, err := os.Open(path)\n    if err != nil { return err }\n    return f.Close()\n}","typeGuard":null,"tryCatchPattern":"if err := vegeta.NewTargets(r); err != nil { \n    if strings.Contains(err.Error(), \"bad body:\") {\n        return fmt.Errorf(\"@-referenced body file unreadable: %w\", err)\n    }\n    return err\n}","preventionTips":["Use absolute paths in @-directives.","Verify body files exist with a pre-flight check in scripts.","Run vegeta from the expected working directory in CI."],"tags":["go","targets","filesystem"],"backgroundTag":"file-not-found","analyzedSha":"cf5811269046c672a604b1eb352204d30f16ae4a","analyzedAt":"2026-08-31T11:04:20.464Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}