{"record":{"id":"13e8f64104a0c3bc","repo":"vitessio/vitess","slug":"expected-d-rows-in-result-got-d","errorCode":null,"errorMessage":"expected %d rows in result, got %d","messagePattern":"expected (.+?) rows in result, got (.+?)","errorType":"error_code","errorClass":"RowMismatchError","httpStatus":null,"severity":"error","filePath":"go/sqltypes/parse_rows.go","lineNumber":140,"sourceCode":"type RowMismatchError struct {\n\terr       error\n\twant, got []Row\n}\n\nfunc (e *RowMismatchError) Error() string {\n\treturn fmt.Sprintf(\"results differ: %v\\n\\twant: %v\\n\\tgot:  %v\", e.err, e.want, e.got)\n}\n\nfunc RowEqual(want, got Row) bool {\n\treturn slices.EqualFunc(want, got, func(a, b Value) bool {\n\t\treturn a.Equal(b)\n\t})\n}\n\nfunc RowsEquals(want, got []Row) error {\n\tif len(want) != len(got) {\n\t\treturn &RowMismatchError{\n\t\t\terr:  fmt.Errorf(\"expected %d rows in result, got %d\", len(want), len(got)),\n\t\t\twant: want,\n\t\t\tgot:  got,\n\t\t}\n\t}\n\n\tmatched := make([]bool, len(want))\n\tfor _, aa := range want {\n\t\tvar ok bool\n\t\tfor i, bb := range got {\n\t\t\tif matched[i] {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif RowEqual(aa, bb) {\n\t\t\t\tmatched[i] = true\n\t\t\t\tok = true\n\t\t\t\tbreak\n\t\t\t}\n\t\t}","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/sqltypes/parse_rows.go#L122-L158","documentation":"RowsEquals compares two row sets unordered. Before matching individual rows it checks the cardinality; if want and got have different lengths it returns a RowMismatchError carrying this message plus both full row sets for diffing.","triggerScenarios":"Calling RowsEquals (directly or via RowsEqualsStr / AssertMatchesNoOrder) when the actual query result returned a different number of rows than the expected set.","commonSituations":"Underlying query changed semantics (added/removed a WHERE clause, missing LIMIT), data set differences between environments, or a streaming test collecting fewer/more rows than expected.","solutions":["Inspect got vs want (RowMismatchError embeds both) to see which side is wrong","Fix the query or fixture data so cardinality matches","Add/adjust a LIMIT or WHERE clause if the test intent is a subset check"],"exampleFix":"// before\nquery := \"select id from t\"\n// after (if only first row intended)\nquery := \"select id from t limit 1\"","handlingStrategy":"type-guard","validationCode":"if len(got) != expectedCount {\n  return fmt.Errorf(\"pre-check: got %d rows, want %d\", len(got), expectedCount)\n}","typeGuard":"func sameCardinality(want, got []sqltypes.Row) bool { return len(want) == len(got) }","tryCatchPattern":"err := sqltypes.RowsEquals(want, got)\nvar rm *sqltypes.RowMismatchError\nif errors.As(err, &rm) {\n  t.Logf(\"want=%v got=%v\", rm.Want, rm.Got)\n}","preventionTips":["Count expected rows explicitly before asserting","Pin LIMIT in queries whose row count should be stable","Check fixtures per environment"],"tags":["testing","assertion","row-count"],"backgroundTag":"row-count-mismatch","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}