vitessio/vitess · error
unrecognized query
Error message
unrecognized query
What it means
fakevtsql.ErrUnrecognizedQuery is returned by QueryContext when the fake vtsql driver receives a query string it was not configured to handle. The fake only responds to queries registered in its expectations; anything else yields this sentinel. It signals a mismatch between the mock setup and the SQL issued.
Source
Thrown at go/vt/vtadmin/vtsql/fakevtsql/conn.go:41
"fmt"
"strings"
"github.com/stretchr/testify/assert"
"vitess.io/vitess/go/vt/topo/topoproto"
"vitess.io/vitess/go/vt/vtadmin/vtadminproto"
vtadminpb "vitess.io/vitess/go/vt/proto/vtadmin"
)
var (
// ErrConnClosed is returend when attempting to query a closed connection.
// It is the identical message to vtsql.ErrConnClosed, but redefined to
// prevent an import cycle in package vtsql's tests.
ErrConnClosed = errors.New("use of closed connection")
// ErrUnrecognizedQuery is returned when QueryCnotext is given a query
// string the mock is not set up to handle.
ErrUnrecognizedQuery = errors.New("unrecognized query")
)
type conn struct {
tablets []*vtadminpb.Tablet
shouldErr bool
}
var (
_ driver.Conn = (*conn)(nil)
_ driver.QueryerContext = (*conn)(nil)
)
func (c *conn) Begin() (driver.Tx, error) {
return nil, nil
}
func (c *conn) Close() error {
return nilView on GitHub (pinned to 01a25a7d17)
Solutions
- Update the fake's registered query/expectation to match the exact query string the code issues
- Compare the actual query text produced by the code with the string registered on the fake
- Regenerate or refresh the test fixture if the SQL in production code changed
Example fix
// before
fake := fakevtsql.New().WithExpectedResults("select id from tablets", rows)
// code now runs "select id, hostname from tablets"
// after
fake := fakevtsql.New().WithExpectedResults("select id, hostname from tablets", rows) Defensive patterns
Strategy: validation
Validate before calling
// ensure the fake knows the exact query before exercising code
fake.WithExpectedResults("select id, hostname from tablets", rows) Type guard
func isUnrecognizedQuery(err error) bool { return errors.Is(err, fakevtsql.ErrUnrecognizedQuery) } Try / catch
rows, err := conn.QueryContext(ctx, q)
if errors.Is(err, fakevtsql.ErrUnrecognizedQuery) {
t.Fatalf("fakevtsql missing expectation for query %q", q)
} Prevention
- Update fake expectations whenever production SQL changes
- Compare exact query strings including whitespace/placeholders
- Add helpers that register expectations from shared constants
- Run tests after any query refactor
When it happens
Trigger: Code under test issues a query string that the fake's expected-query map does not contain; whitespace/placeholder differences make the strings unequal; a new query was added to production code without updating the test fixture.
Common situations: Writing or updating vtadmin unit tests after changing a SQL statement; typos in test expectations; normalization mismatches between the query as written and as configured.
Related errors
- use of closed connection
- bad sql row
- err rows closed
- not allowed: deny-all security-policy enforced
- not allowed: read-only security-policy enforced
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/bda293d0ad05a9c6.
Report an issue: GitHub.