{"record":{"id":"74c43575c751201b","repo":"tsenart/vegeta","slug":"bad-url-s-w","errorCode":null,"errorMessage":"bad URL: %s, %w","messagePattern":"bad URL: (.+?), %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/targets.go","lineNumber":300,"sourceCode":"\t\t\t}\n\t\t}\n\n\t\ttgt.Body = body\n\t\ttgt.Header = http.Header{}\n\t\tfor k, vs := range hdr {\n\t\t\ttgt.Header[k] = vs\n\t\t}\n\n\t\ttokens := strings.SplitN(line, \" \", 2)\n\t\tif len(tokens) < 2 {\n\t\t\treturn fmt.Errorf(\"bad target: %s\", line)\n\t\t}\n\t\tif !startsWithHTTPMethod(line) {\n\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)","sourceCodeStart":282,"sourceCodeEnd":318,"githubUrl":"https://github.com/tsenart/vegeta/blob/cf5811269046c672a604b1eb352204d30f16ae4a/lib/targets.go#L282-L318","documentation":"Returned when the URL portion of a target line fails url.ParseRequestURI. The method was valid but the second token is not a parseable absolute request URI.","triggerScenarios":"Target lines with malformed URLs: missing scheme (\"GET localhost:8080/\"), invalid characters or spaces in the URL, or an empty URL token.","commonSituations":"Writing relative paths instead of absolute URLs in targets files, unencoded special characters (#, spaces, quotes) in URLs, shell variable expansion gone wrong leaving \"\" or partial URLs.","solutions":["Provide an absolute URL including scheme and host, e.g. \"GET http://localhost:8080/path\".","Percent-encode or quote special characters in the URL.","Inspect the URL text shown in the error and run it through url.ParseRequestURI locally to confirm validity.","Shell-quote URLs containing ? and & so the targets file ends up intact."],"exampleFix":"// before\nGET localhost:8080/hello?a=1&b=2\n// after\nGET http://localhost:8080/hello?a=1&b=2","handlingStrategy":"validation","validationCode":"func validURL(u string) error {\n    _, err := url.ParseRequestURI(u)\n    return err\n}\n// ensure scheme present\nfunc hasScheme(u string) bool { return strings.HasPrefix(u, \"http://\") || strings.HasPrefix(u, \"https://\") }","typeGuard":null,"tryCatchPattern":"if _, err := vegeta.NewTargets(r); err != nil {\n    if strings.Contains(err.Error(), \"bad URL:\") {\n        return fmt.Errorf(\"targets need absolute http(s) URLs: %w\", err)\n    }\n    return err\n}","preventionTips":["Always include scheme and host in target URLs.","Quote URLs with special chars (?, &, #) in scripts.","Reject relative paths in targets files during linting."],"tags":["go","targets","url"],"backgroundTag":"invalid-target-format","analyzedSha":"cf5811269046c672a604b1eb352204d30f16ae4a","analyzedAt":"2026-08-31T11:04:20.464Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}