{"id":"b6ccef3685d06849","repo":"jackc/pgx","slug":"w-d-needed-at-offset-d-d-remain","errorCode":null,"errorMessage":"%w: %d needed at offset %d, %d remain","messagePattern":"%w: (.+?) needed at offset (.+?), (.+?) remain","errorType":"exception","errorClass":"ErrInsufficientBytes","httpStatus":null,"severity":"error","filePath":"internal/pgio/read.go","lineNumber":57,"sourceCode":"\n// need reports whether n more bytes are available, recording an error if not.\n//\n// The error is built by failShort rather than here so that need stays within\n// the inliner's budget. Reads of fixed-size values are the hottest path in the\n// driver, and an un-inlined bounds check costs more than the read itself.\nfunc (r *Reader) need(n int) bool {\n\tif r.err != nil {\n\t\treturn false\n\t}\n\tif len(r.s)-r.rp < n {\n\t\tr.failShort(n)\n\t\treturn false\n\t}\n\treturn true\n}\n\nfunc (r *Reader) failShort(n int) {\n\tr.fail(fmt.Errorf(\"%w: %d needed at offset %d, %d remain\", ErrInsufficientBytes, n, r.rp, len(r.s)-r.rp))\n}\n\n// Err returns the first error encountered, if any.\nfunc (r *Reader) Err() error {\n\treturn r.err\n}\n\n// Remaining returns the number of unread bytes.\nfunc (r *Reader) Remaining() int {\n\treturn len(r.s) - r.rp\n}\n\nfunc (r *Reader) Byte() byte {\n\tif !r.need(1) {\n\t\treturn 0\n\t}\n\tb := r.s[r.rp]\n\tr.rp += 1","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/internal/pgio/read.go#L39-L75","documentation":"Error \"%w: %d needed at offset %d, %d remain\" thrown in jackc/pgx.","triggerScenarios":"Thrown at internal/pgio/read.go:57 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}