{"id":"21e71eff5b030dcb","repo":"jackc/pgx","slug":"d-unexpected-trailing-bytes-at-offset-d","errorCode":null,"errorMessage":"%d unexpected trailing bytes at offset %d","messagePattern":"(.+?) unexpected trailing bytes at offset (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/pgio/read.go","lineNumber":208,"sourceCode":"\t\treturn nil, false\n\t}\n\treturn r.Bytes(int(length)), false\n}\n\n// Finish returns the first error encountered, or an error if unread bytes\n// remain. Decoders that must consume the entire source should end with Finish.\nfunc (r *Reader) Finish() error {\n\tif r.err != nil {\n\t\treturn r.err\n\t}\n\tif r.rp != len(r.s) {\n\t\treturn r.errTrailing()\n\t}\n\treturn nil\n}\n\nfunc (r *Reader) errTrailing() error {\n\treturn fmt.Errorf(\"%d unexpected trailing bytes at offset %d\", len(r.s)-r.rp, r.rp)\n}\n\n// ErrInvalidLength is wrapped by the errors returned from the exact-length\n// read functions below.\nvar ErrInvalidLength = errors.New(\"invalid length\")\n\nfunc errLength(want, got int) error {\n\treturn fmt.Errorf(\"%w: expected %d bytes, got %d\", ErrInvalidLength, want, got)\n}\n\n// The Uint*Exact functions read a single fixed-size value that makes up an\n// entire message, which is what the scan plans for the fixed-size PostgreSQL\n// types receive. They are the counterpart to Reader for values that have no\n// internal structure: there is no position to track and no error to make\n// sticky, just an exact-length assertion the caller cannot skip. Keeping them\n// separate from Reader is deliberate — these are the hottest decode paths in\n// the driver and they are small enough for the compiler to inline, which a\n// Reader method carrying a bounds check and a read pointer is not.","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/internal/pgio/read.go#L190-L226","documentation":"Error \"%d unexpected trailing bytes at offset %d\" thrown in jackc/pgx.","triggerScenarios":"Thrown at internal/pgio/read.go:208 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"ec1a0befd22592cffffdeeb0a50311b506372f4c","analyzedAt":"2026-08-04T22:52:11.263Z","schemaVersion":2}