{"record":{"id":"6fa7558f6575fbfb","repo":"golang/go","slug":"error-reading-preprocessed-profile-w","errorCode":null,"errorMessage":"error reading preprocessed profile: %w","messagePattern":"error reading preprocessed profile: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/internal/pgo/deserialize.go","lineNumber":40,"sourceCode":"\t\t// Empty file.\n\t\treturn false, nil\n\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}","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/internal/pgo/deserialize.go#L22-L58","documentation":"In FromSerialized, the very first scanner.Scan() returned false (no token) AND scanner.Err() is non-nil — i.e. an I/O or scanner error occurred while reading the header line, distinct from a clean empty file (1276) or a wrong header (1277).","triggerScenarios":"bufio.Scanner returns an error on the first Scan call against the profile stream — e.g. a line longer than the scanner buffer, or an underlying read error.","commonSituations":"A profile with an extremely long header line exceeding the default scanner token limit, or a corrupted/partially-flushed profile file.","solutions":["Regenerate the profile with Profile.WriteTo to ensure it is well-formed.","If lines may be long, supply a scanner with a larger buffer.","Verify the file is complete and not truncated."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Confirm non-empty and well-formed before FromSerialized.\n// fi, err := os.Stat(path)\n// if err != nil { return err }\n// if fi.Size() == 0 { return errors.New(\"profile empty\") }","typeGuard":null,"tryCatchPattern":"// prof, err := pgo.FromSerialized(r)\n// if err != nil && strings.Contains(err.Error(), \"error reading preprocessed profile\") {\n//     // I/O error on header; regenerate the profile\n//     return err\n// }","preventionTips":["Regenerate profiles with Profile.WriteTo.","Supply a scanner with a larger buffer if header lines may be long.","Verify the profile file is complete before parsing."],"tags":["pgo","profile","deserialize","io"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}