vitessio/vitess · error
failed to parse literal string at %s: %w
Error message
failed to parse literal string at %s: %w
What it means
ParseRows parses a text representation of rows (e.g. "('a', 1), ('b', 2)") into []sqltypes.Row. When a token is scanned as a quoted string, it is run through strconv.Unquote; if the literal is not a valid Go-quoted string, this error is returned wrapping the underlying unquote failure plus the scan position.
Source
Thrown at go/sqltypes/parse_rows.go:102
var ok bool
vtype, ok = querypb.Type_value[ident]
if !ok {
return nil, fmt.Errorf("unknown SQL type %q at %s", ident, scan.Position)
}
next = stInValue0
}
case stInValue0:
if tok == '(' {
next = stInValue1
}
case stInValue1:
literal := scan.TokenText()
switch tok {
case scanner.String:
var err error
literal, err = strconv.Unquote(literal)
if err != nil {
return nil, fmt.Errorf("failed to parse literal string at %s: %w", scan.Position, err)
}
fallthrough
case scanner.Int, scanner.Float:
row = append(row, MakeTrusted(Type(vtype), []byte(literal)))
next = stInValue2
}
case stInValue2:
if tok == ')' {
next = stInRow
}
}
if next == stInvalid {
return nil, fmt.Errorf("unexpected token '%s' at %s", scan.TokenText(), scan.Position)
}
st = next
}
return nil, io.ErrUnexpectedEOF
}View on GitHub (pinned to 01a25a7d17)
Solutions
- Fix the string literal in the expected-rows text so it is a valid Go double-quote... actually a valid single-quoted string with valid escapes (e.g. ('ok'))
- Escape backslashes and quotes correctly inside the literal
- Print the wrapped strconv error and scan.Position to locate the offending literal
Example fix
// before
want := "('it's', 1)"
// after
want := "('it\\'s', 1)" Defensive patterns
Strategy: validation
Validate before calling
func validLiterals(s string) bool {
for _, part := range strings.Split(s, ",") {
p := strings.TrimSpace(part)
if strings.HasPrefix(p, "'") && !strings.HasSuffix(p, "')") { return false }
}
return true
} Try / catch
want, err := sqltypes.ParseRows(wantStr)
if err != nil {
var posErr = err // includes scan.Position
t.Fatalf("bad fixture %q: %v", wantStr, err)
} Prevention
- Keep expected-row strings as valid single-quoted literals with doubled-backslash escapes
- Avoid hand-editing assertion strings; regenerate from actual output
- Run assertions locally before CI
When it happens
Trigger: Calling ParseRows (directly or via RowsEqualsStr/AssertMatchesNoOrder) with a test-matcher string containing a malformed quoted string literal, e.g. unmatched quote or invalid escape sequence like ('it\'s) written incorrectly.
Common situations: Writing test assertions where the expected-row string was hand-edited and a quote or backslash escape got broken; copying SQL-style literals that use doubled quotes ('') which strconv.Unquote rejects.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- unexpected token '%s' at %s
- malformed row assertion: %w
- stray %% at the end of pattern
- overflow
- too many .s
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/95d25bc029c45dcd.
Report an issue: GitHub.