{"record":{"id":"71a841b63ad0da15","repo":"golang-migrate/migrate","slug":"can-t-read-limit-argument-n","errorCode":null,"errorMessage":"can't read limit argument N","messagePattern":"can't read limit argument N","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cli/commands.go","lineNumber":242,"sourceCode":"\n// numDownMigrationsFromArgs returns an int for number of migrations to apply\n// and a bool indicating if we need a confirm before applying\nfunc numDownMigrationsFromArgs(applyAll bool, args []string) (int, bool, error) {\n\tif applyAll {\n\t\tif len(args) > 0 {\n\t\t\treturn 0, false, errors.New(\"-all cannot be used with other arguments\")\n\t\t}\n\t\treturn -1, false, nil\n\t}\n\n\tswitch len(args) {\n\tcase 0:\n\t\treturn -1, true, nil\n\tcase 1:\n\t\tdownValue := args[0]\n\t\tn, err := strconv.ParseUint(downValue, 10, 64)\n\t\tif err != nil {\n\t\t\treturn 0, false, errors.New(\"can't read limit argument N\")\n\t\t}\n\t\treturn int(n), false, nil\n\tdefault:\n\t\treturn 0, false, errors.New(\"too many arguments\")\n\t}\n}\n","sourceCodeStart":224,"sourceCodeEnd":249,"githubUrl":"https://github.com/golang-migrate/migrate/blob/01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a/internal/cli/commands.go#L224-L249","documentation":"When `migrate down N` is given a positional argument that is not a valid unsigned integer, numDownMigrationsFromArgs fails strconv.ParseUint(downValue, 10, 64) and returns 'can't read limit argument N'. The library treats the single argument as the number of migrations to roll back, so it must parse as a base-10 uint64.","triggerScenarios":"Running `migrate down abc`, `down 3.5`, `down -1`, or `down 99999999999999999999` (overflow) so ParseUint returns an error.","commonSituations":"Passing a variable that is empty or non-numeric in scripts; a negative count that users expect to mean 'last N'; pasting commands where the argument is a migration filename instead of a count.","solutions":["Pass a non-negative integer, e.g. `migrate down 1`.","Validate the value in wrapper scripts (regex ^[0-9]+$) before invoking the CLI.","Use -all instead of a numeric argument when you intend to revert everything.","Check the variable supplying N — empty strings and floats are common culprits."],"exampleFix":"// before\nmigrate -path ./migrations -database $DB down \"$STEPS\"\n// after\ncase \"$STEPS\" in ''|*[!0-9]*) echo \"STEPS must be a positive integer\"; exit 1;; esac\nmigrate -path ./migrations -database $DB down \"$STEPS\"","handlingStrategy":"validation","validationCode":"case \"$N\" in ''|*[!0-9]*) echo \"N must be a non-negative integer\"; exit 1;; esac","typeGuard":"func isCount(s string) bool {\n\t_, err := strconv.ParseUint(s, 10, 64)\n\treturn err == nil\n}","tryCatchPattern":null,"preventionTips":["Always pass down a plain integer argument","Validate user/script input with a ^[0-9]+$ check before invoking the CLI","Use -all instead of a number when you intend to roll back everything"],"tags":["go","cli","golang-migrate","invalid-argument","parsing"],"backgroundTag":"invalid-argument","analyzedSha":"01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a","analyzedAt":"2026-09-02T19:38:29.671Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}