{"record":{"id":"98451fd313011a8d","repo":"golang-migrate/migrate","slug":"digits-must-be-positive","errorCode":null,"errorMessage":"digits must be positive","messagePattern":"digits must be positive","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cli/commands.go","lineNumber":18,"sourceCode":"package cli\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"strconv\"\n\t\"strings\"\n\t\"time\"\n\n\t\"github.com/golang-migrate/migrate/v4\"\n\t_ \"github.com/golang-migrate/migrate/v4/database/stub\" // TODO remove again\n\t_ \"github.com/golang-migrate/migrate/v4/source/file\"\n)\n\nvar (\n\terrInvalidSequenceWidth     = errors.New(\"digits must be positive\")\n\terrIncompatibleSeqAndFormat = errors.New(\"the seq and format options are mutually exclusive\")\n\terrInvalidTimeFormat        = errors.New(\"time format may not be empty\")\n)\n\nfunc nextSeqVersion(matches []string, seqDigits int) (string, error) {\n\tif seqDigits <= 0 {\n\t\treturn \"\", errInvalidSequenceWidth\n\t}\n\n\tnextSeq := uint64(1)\n\n\tif len(matches) > 0 {\n\t\tfilename := matches[len(matches)-1]\n\t\tmatchSeqStr := filepath.Base(filename)\n\t\tidx := strings.Index(matchSeqStr, \"_\")\n\n\t\tif idx < 1 { // Using 1 instead of 0 since there should be at least 1 digit\n\t\t\treturn \"\", fmt.Errorf(\"malformed migration filename: %s\", filename)","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/golang-migrate/migrate/blob/01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a/internal/cli/commands.go#L1-L36","documentation":"errInvalidSequenceWidth ('digits must be positive') is returned by nextSeqVersion in internal/cli when the migrate create -seq command is invoked with a -digits value <= 0. Sequential migration version numbers are zero-padded to the given width, so at least one digit is required. It is package-private and returned to TestNextSeqVersion/TestCreateCmd.","triggerScenarios":"Running `migrate create -seq -digits 0` or `-digits -1 ...` (any digits value not a positive integer) so nextSeqVersion receives seqDigits <= 0.","commonSituations":"Scripting the CLI with a computed digits value that ends up 0; typo like -digits 0 when trying to get unpadded output; templated CI pipelines with an unset/empty variable defaulting to 0.","solutions":["Pass a positive -digits value, e.g. -digits 4 (the default width).","Omit the -digits flag to use the default.","Validate the digits value in your wrapper script before invoking the CLI.","If digits is sourced from a variable, check it is a positive integer first."],"exampleFix":"// before\nmigrate create -seq -digits 0 -ext sql -dir migrations add_users\n// after\nmigrate create -seq -digits 4 -ext sql -dir migrations add_users","handlingStrategy":"validation","validationCode":"if [ -n \"$DIGITS\" ] && [ \"$DIGITS\" -le 0 ] 2>/dev/null; then\n\techo \"-digits must be a positive integer\"; exit 1\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Omit -digits and rely on the default width unless you need a specific padding","Validate computed/interpolated digits values in wrapper scripts before invoking the CLI","Remember version numbers zero-pad; digits must be >= 1"],"tags":["go","cli","golang-migrate","invalid-argument"],"backgroundTag":"invalid-argument","analyzedSha":"01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a","analyzedAt":"2026-09-02T19:38:29.671Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}