jackc/pgx · error

empty range

Error message

empty range: %w

What it means

The binary range is marked empty but carries trailing bytes after the flags byte; r.Finish() failed and the error is wrapped with %w. A malformed empty-range payload from the server is the faulting input.

Solutions

  1. Reject the malformed empty-range encoding
  2. Verify the writer produced exactly one byte for empty ranges
  3. Diagnose the payload producer if extra bytes keep appearing
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pgtype/range.go:214 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of jackc/pgx@ec1a0befd2 (2026-08-04). Data as JSON: /api/errors/082a47c5960950e4. Report an issue: GitHub.

Appendix: source

Thrown at pgtype/range.go:214

	emptyMask          = 1
	lowerInclusiveMask = 2
	upperInclusiveMask = 4
	lowerUnboundedMask = 8
	upperUnboundedMask = 16
)

func parseUntypedBinaryRange(src []byte) (*untypedBinaryRange, error) {
	ubr := &untypedBinaryRange{}
	r := pgio.NewReader(src)

	rangeType := r.Byte()
	if r.Err() != nil {
		return nil, fmt.Errorf("range too short: %v", len(src))
	}

	if rangeType&emptyMask > 0 {
		if err := r.Finish(); err != nil {
			return nil, fmt.Errorf("empty range: %w", err)
		}
		ubr.LowerType = Empty
		ubr.UpperType = Empty
		return ubr, nil
	}

	switch {
	case rangeType&lowerInclusiveMask > 0:
		ubr.LowerType = Inclusive
	case rangeType&lowerUnboundedMask > 0:
		ubr.LowerType = Unbounded
	default:
		ubr.LowerType = Exclusive
	}

	switch {
	case rangeType&upperInclusiveMask > 0:
		ubr.UpperType = Inclusive

View on GitHub (pinned to ec1a0befd2)