{"record":{"id":"33d526e419de417f","repo":"golang/go","slug":"preprocessed-profile-missing-header","errorCode":null,"errorMessage":"preprocessed profile missing header","messagePattern":"preprocessed profile missing header","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/internal/pgo/deserialize.go","lineNumber":42,"sourceCode":"\t} else if err != nil {\n\t\treturn false, fmt.Errorf(\"error reading profile header: %w\", err)\n\t}\n\n\treturn string(hdr) == serializationHeader, nil\n}\n\n// FromSerialized parses a profile from serialization output of Profile.WriteTo.\nfunc FromSerialized(r io.Reader) (*Profile, error) {\n\td := emptyProfile()\n\n\tscanner := bufio.NewScanner(r)\n\tscanner.Split(bufio.ScanLines)\n\n\tif !scanner.Scan() {\n\t\tif err := scanner.Err(); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error reading preprocessed profile: %w\", err)\n\t\t}\n\t\treturn nil, fmt.Errorf(\"preprocessed profile missing header\")\n\t}\n\tif gotHdr := scanner.Text() + \"\\n\"; gotHdr != serializationHeader {\n\t\treturn nil, fmt.Errorf(\"preprocessed profile malformed header; got %q want %q\", gotHdr, serializationHeader)\n\t}\n\n\tfor scanner.Scan() {\n\t\treadStr := scanner.Text()\n\n\t\tcallerName := readStr\n\n\t\tif !scanner.Scan() {\n\t\t\tif err := scanner.Err(); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"error reading preprocessed profile: %w\", err)\n\t\t\t}\n\t\t\treturn nil, fmt.Errorf(\"preprocessed profile entry missing callee\")\n\t\t}\n\t\tcalleeName := scanner.Text()\n","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/internal/pgo/deserialize.go#L24-L60","documentation":"FromSerialized's first scanner.Scan() returned false with no scanner error, meaning the stream is empty (no header line at all). A valid serialized PGO profile must begin with the serialization header line, so an empty file is rejected.","triggerScenarios":"Passing an empty (zero-byte) or whitespace-only reader to FromSerialized.","commonSituations":"Pointing -pgoprofile (or a tool's profile input) at an empty file, a file path that was created but never written, or a truncated-to-zero profile.","solutions":["Regenerate the profile so it actually contains serialized data.","Verify the profile path is correct and the file is non-empty.","Guard with IsSerialized first to distinguish 'empty' from 'wrong format'."],"exampleFix":"// before\nprof, err := pgo.FromSerialized(bytes.NewReader(nil))\n\n// after: validate before parsing\nok, err := pgo.IsSerialized(bufReader)\nif err != nil { return err }\nif !ok { return errors.New(\"profile is empty or not serialized\") }\nprof, err := pgo.FromSerialized(bufReader)","handlingStrategy":"validation","validationCode":"// Distinguish empty from wrong-format up front.\n// ok, err := pgo.IsSerialized(bufio.NewReader(bytes.NewReader(data)))\n// if err != nil { return err }\n// if !ok { return errors.New(\"profile is empty or not a serialized PGO profile\") }","typeGuard":null,"tryCatchPattern":"// prof, err := pgo.FromSerialized(r)\n// if err != nil {\n//     if err.Error() == \"preprocessed profile missing header\" {\n//         // empty input; check the file path/size\n//     }\n//     return err\n// }","preventionTips":["Call IsSerialized before FromSerialized.","Verify the profile path exists and is non-empty.","Regenerate profiles that come back empty."],"tags":["pgo","profile","empty-file","deserialize"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}