jackc/pgx · error

invalid length for Path

Error message

invalid length for Path: %w

What it means

When decoding a binary path, the closed flag byte is read first and then the point count is derived from the remaining length divided by 16 (two float64s per point). This wrapper fires when the reader signals an error during that computation — the payload is too short to contain even the header byte plus whole points, i.e. a truncated binary path.

Solutions

  1. Verify the binary path value is complete and well-formed
  2. Use text format for the path column
  3. Check custom binary encoding if the value was client-produced
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pgtype/path.go:186 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/c7617d98405e12d9. Report an issue: GitHub.

Appendix: source

Thrown at pgtype/path.go:186

	return nil
}

type scanPlanBinaryPathToPathScanner struct{}

func (scanPlanBinaryPathToPathScanner) Scan(src []byte, dst any) error {
	scanner := (dst).(PathScanner)

	if src == nil {
		return scanner.ScanPath(Path{})
	}

	r := pgio.NewReader(src)

	closed := r.Byte() == 1
	// Each point is two float64s.
	pointCount := r.Count(16)
	if err := r.Err(); err != nil {
		return fmt.Errorf("invalid length for Path: %w", err)
	}

	points := make([]Vec2, pointCount)
	for i := range points {
		x := r.Uint64()
		y := r.Uint64()
		points[i] = Vec2{math.Float64frombits(x), math.Float64frombits(y)}
	}

	if err := r.Finish(); err != nil {
		return fmt.Errorf("invalid length for Path with %d points: %w", pointCount, err)
	}

	return scanner.ScanPath(Path{
		P:      points,
		Closed: closed,
		Valid:  true,
	})

View on GitHub (pinned to ec1a0befd2)