jackc/pgx · error

expected '%c' ('%#v'); found end

Error message

expected '%c' ('%#v'); found end

What it means

consumeExpectedByte hit the end of the hstore string before finding the required delimiter byte (e.g. '=' between key and value, or ',' between pairs). The truncated hstore text is at fault; the message names the byte that was expected.

Solutions

  1. Fix the truncated hstore literal so it is complete
  2. Check for truncation when the string was produced or transported
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pgtype/hstore.go:299 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/6a0d5b2665d4f279. Report an issue: GitHub.

Appendix: source

Thrown at pgtype/hstore.go:299

// consume returns the next byte of the string, or end if the string is done.
func (p *hstoreParser) consume() (b byte, end bool) {
	if p.pos >= len(p.str) {
		return 0, true
	}
	b = p.str[p.pos]
	p.pos++
	return b, false
}

func unexpectedByteErr(actualB, expectedB byte) error {
	return fmt.Errorf("expected '%c' ('%#v'); found '%c' ('%#v')", expectedB, expectedB, actualB, actualB)
}

// consumeExpectedByte consumes expectedB from the string, or returns an error.
func (p *hstoreParser) consumeExpectedByte(expectedB byte) error {
	nextB, end := p.consume()
	if end {
		return fmt.Errorf("expected '%c' ('%#v'); found end", expectedB, expectedB)
	}
	if nextB != expectedB {
		return unexpectedByteErr(nextB, expectedB)
	}
	return nil
}

// consumeExpected2 consumes two expected bytes or returns an error.
// This was a bit faster than using a string argument (better inlining? Not sure).
func (p *hstoreParser) consumeExpected2(one, two byte) error {
	if p.pos+2 > len(p.str) {
		return errors.New("unexpected end of string")
	}
	if p.str[p.pos] != one {
		return unexpectedByteErr(p.str[p.pos], one)
	}
	if p.str[p.pos+1] != two {
		return unexpectedByteErr(p.str[p.pos+1], two)

View on GitHub (pinned to ec1a0befd2)