{"record":{"id":"668c4b50d78fb8aa","repo":"vitessio/vitess","slug":"invalid-limit-value-d-maximum-number-of-rows","errorCode":null,"errorMessage":"invalid --limit value (%d), maximum number of rows to compare needs to be greater than 0","messagePattern":"invalid --limit value \\((.+?)\\), maximum number of rows to compare needs to be greater than 0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtctl/vdiff2.go","lineNumber":105,"sourceCode":"\t\tif action != vdiff.CreateAction {\n\t\t\treturn usage\n\t\t}\n\tcase 3:\n\t\taction = vdiff.VDiffAction(strings.ToLower(subFlags.Arg(1)))\n\t\tactionArg = strings.ToLower(subFlags.Arg(2))\n\tdefault:\n\t\treturn usage\n\t}\n\tif action == \"\" {\n\t\treturn fmt.Errorf(\"invalid action '%s'; %s\", subFlags.Arg(1), usage)\n\t}\n\tkeyspace, workflowName, err := splitKeyspaceWorkflow(subFlags.Arg(0))\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif *maxRows <= 0 {\n\t\treturn fmt.Errorf(\"invalid --limit value (%d), maximum number of rows to compare needs to be greater than 0\", *maxRows)\n\t}\n\n\toptions := &tabletmanagerdatapb.VDiffOptions{\n\t\tPickerOptions: &tabletmanagerdatapb.VDiffPickerOptions{\n\t\t\tTabletTypes: *tabletTypes,\n\t\t\tSourceCell:  *sourceCell,\n\t\t\tTargetCell:  *targetCell,\n\t\t},\n\t\tCoreOptions: &tabletmanagerdatapb.VDiffCoreOptions{\n\t\t\tTables:                *tables,\n\t\t\tAutoRetry:             *autoRetry,\n\t\t\tMaxRows:               *maxRows,\n\t\t\tChecksum:              *checksum,\n\t\t\tSamplePct:             *samplePct,\n\t\t\tTimeoutSeconds:        int64(timeout.Seconds()),\n\t\t\tMaxExtraRowsToCompare: *maxExtraRowsToCompare,\n\t\t\tUpdateTableStats:      *updateTableStats,\n\t\t},","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtctl/vdiff2.go#L87-L123","documentation":"VDiff validates the --limit flag (bound to maxRows) before starting a diff: rows-to-compare must be a positive integer. Non-positive values produce this explicit error naming the flag and the received value.","triggerScenarios":"Running `VDiff -- ks.wf <action> --limit 0` or `--limit -1` (or a value that flag parsing left at a non-positive default) so the `*maxRows <= 0` check fires.","commonSituations":"Script-generated commands where the limit is computed and can evaluate to 0 (empty result of a count query); confusing --limit semantics and setting it to 0 to mean 'unlimited' (it does not — omit or use a large positive value instead).","solutions":["Pass a positive integer, e.g. `--limit 10000`.","If you intended unlimited comparison, remove the --limit flag entirely rather than setting 0.","Fix the shell/script expression that computes the limit so it cannot yield 0 or negative values.","Verify the flag actually reached VDiff — flag types default to 0, so a misspelled flag name silently leaves maxRows at 0."],"exampleFix":"// before\nVDiff -- commerce.sell show all --limit 0\n// after\nVDiff -- commerce.sell show all --limit 100","handlingStrategy":"validation","validationCode":"if limit <= 0 {\n    return fmt.Errorf(\"--limit must be > 0 (got %d); omit the flag for unlimited\", limit)\n}","typeGuard":null,"tryCatchPattern":"if err := runVDiff(args); err != nil {\n    var se *vterrors.VitessError\n    if strings.Contains(err.Error(), \"invalid --limit value\") {\n        log.Warn(\"fix the computed limit before retrying\", slog.Any(\"error\", err))\n    }\n}","preventionTips":["Never use 0 to mean 'unlimited' — omit --limit instead.","When computing the limit in scripts, clamp: if v <= 0 { v = defaultLimit }.","Beware default 0 from a misspelled or unregistered flag."],"tags":["vtctl","vdiff","flag-validation"],"backgroundTag":"invalid-flag-value","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}