{"record":{"id":"4423d11928f9f186","repo":"tsenart/vegeta","slug":"encode-can-t-detect-encoding-of-q","errorCode":null,"errorMessage":"encode: can't detect encoding of %q","messagePattern":"encode: can't detect encoding of %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"file.go","lineNumber":38,"sourceCode":"\t\tif create {\n\t\t\treturn os.Create(name)\n\t\t}\n\t\treturn os.Open(name)\n\t}\n}\n\nfunc decoder(files []string) (vegeta.Decoder, io.Closer, error) {\n\tcloser := make(multiCloser, 0, len(files))\n\tdecs := make([]vegeta.Decoder, 0, len(files))\n\tfor _, f := range files {\n\t\trc, err := file(f, false)\n\t\tif err != nil {\n\t\t\treturn nil, closer, err\n\t\t}\n\n\t\tdec := vegeta.DecoderFor(rc)\n\t\tif dec == nil {\n\t\t\treturn nil, closer, fmt.Errorf(\"encode: can't detect encoding of %q\", f)\n\t\t}\n\n\t\tdecs = append(decs, dec)\n\t\tcloser = append(closer, rc)\n\t}\n\treturn vegeta.NewRoundRobinDecoder(decs...), closer, nil\n}\n\ntype multiCloser []io.Closer\n\nfunc (mc multiCloser) Close() error {\n\tvar errs []string\n\tfor _, c := range mc {\n\t\tif err := c.Close(); err != nil {\n\t\t\terrs = append(errs, err.Error())\n\t\t}\n\t}\n","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/tsenart/vegeta/blob/cf5811269046c672a604b1eb352204d30f16ae4a/file.go#L20-L56","documentation":"decoder() (in file.go) sniffs the encoding of each input file using vegeta.DecoderFor; if it cannot detect a known encoding (gob, csv, json) it returns this error with the filename. It is raised by encode, plotRun, and report whenever their input results file(s) are in an unrecognized format.","triggerScenarios":"Passing an input file (-inputs / results file) that is empty, truncated, or not in gob/csv/json result format — e.g. an HTML error page saved by a failed curl, a log file, or a partially written results file.","commonSituations":"Feeding `vegeta report`/`plot` a file that was actually stdout text, not attack output; corrupted or zero-byte results from an aborted attack; piping results through a transform that changed the format; giving -inputs a targets file by mistake.","solutions":["Check the file is non-empty and is a vegeta results file (gob, csv, or json) — `file <path>` and inspect the head.","Regenerate the results with `vegeta attack -output=results.bin` and pass that file as input.","If the data is in another format, convert it to one of gob/csv/json first; ensure the correct extension-free content (DecoderFor sniffs content, not names)."],"exampleFix":"// before\nvegeta report output.txt   # actually a plain log, not results\n// after\nvegeta attack -output=results.bin -duration=10s ...\nvegeta report results.bin","handlingStrategy":"validation","validationCode":"st, err := os.Stat(path)\nif err != nil || st.Size() == 0 {\n    return fmt.Errorf(\"input %q missing or empty\", path)\n}\n// ensure the file is a vegeta results file (gob/csv/json), not logs or targets\nhead, _ := readHead(path, 16)\nif !looksLikeGobCSVOrJSON(head) {\n    return fmt.Errorf(\"input %q is not a vegeta results file\", path)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only feed attack output files (-output results) to report/plot/encode.","Verify inputs are non-empty after long runs; an aborted attack can produce empty files.","Do not pass log files, HTML error pages, or targets files as results inputs."],"tags":["cli","encoding","validation","input-format"],"backgroundTag":"unknown-encoding-format","analyzedSha":"cf5811269046c672a604b1eb352204d30f16ae4a","analyzedAt":"2026-08-31T11:04:20.464Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}