jackc/pgx · error

invalid format for Path

Error message

invalid format for Path

What it means

Textual path parsing walks the inner string expecting a sequence of '(x,y)' point groups; at each step the next character must open a point and each point must close with ')' and contain a comma. This guard fires at any of those expectation failures — the content between the outer delimiters is not a comma-separated list of parenthesized coordinate pairs.

Solutions

  1. Store paths in canonical '((x1,y1),(x2,y2))' or '[...]' text form
  2. Validate and normalize path strings before insertion
  3. Use binary format encoding for path columns
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

Thrown at pgtype/path.go:228

	scanner := (dst).(PathScanner)

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

	if len(src) < 7 {
		return fmt.Errorf("invalid length for Path: %v", len(src))
	}

	closed := src[0] == '('
	points := make([]Vec2, 0)

	// Expected format: ((x1,y1),...,(xn,yn)) or [(x1,y1),...,(xn,yn)]
	str := string(src[1 : len(src)-1])

	for {
		if len(str) == 0 || str[0] != '(' {
			return fmt.Errorf("invalid format for Path")
		}
		body, rest, found := strings.Cut(str[1:], ")")
		if !found {
			return fmt.Errorf("invalid format for Path")
		}

		sx, sy, found := strings.Cut(body, ",")
		if !found {
			return fmt.Errorf("invalid format for Path")
		}
		x, err := strconv.ParseFloat(sx, 64)
		if err != nil {
			return err
		}
		y, err := strconv.ParseFloat(sy, 64)
		if err != nil {
			return err
		}

View on GitHub (pinned to ec1a0befd2)