{"record":{"id":"d48d8443984bea1a","repo":"golang-migrate/migrate","slug":"time-format-may-not-be-empty","errorCode":null,"errorMessage":"time format may not be empty","messagePattern":"time format may not be empty","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cli/commands.go","lineNumber":20,"sourceCode":"\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)\n\t\t}\n","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/golang-migrate/migrate/blob/01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a/internal/cli/commands.go#L2-L38","documentation":"errInvalidTimeFormat ('time format may not be empty') is returned by timeVersion when `migrate create` runs without -seq but with an empty -format string. Time-based versioning derives the version from startTime using the given format; an empty format cannot produce a version, so the command fails early.","triggerScenarios":"Running `migrate create -format \"\" ...` or a wrapper that always passes a -format value which is unset/empty; timeVersion's switch receives format \"\" and sets err = errInvalidTimeFormat.","commonSituations":"CI templates with an interpolatable format variable that resolves to empty; quoting mistakes that yield a zero-length argument; users omitting -format while their wrapper still forwards the flag with an empty value.","solutions":["Pass a valid -format, e.g. -format unix, -format unixNano, or a Go time layout like 20060102150405.","Drop the empty -format flag entirely to use the default time format.","Fix the wrapper/CI variable so a non-empty format is supplied.","Validate the format value in your script before invoking migrate create."],"exampleFix":"// before\nmigrate create -format \"\" -ext sql -dir migrations add_index\n// after\nmigrate create -format unix -ext sql -dir migrations add_index","handlingStrategy":"validation","validationCode":"if [ -n \"${FORMAT+x}\" ] && [ -z \"$FORMAT\" ]; then\n\techo \"FORMAT must be non-empty (unix, unixNano, or a Go time layout)\"; exit 1\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use explicit formats: -format unix, -format unixNano, or a Go time layout","In CI wrappers, substitute defaults for empty variables instead of passing empty strings","Drop the flag entirely rather than passing -format \"\""],"tags":["go","cli","golang-migrate","empty-argument"],"backgroundTag":"invalid-argument","analyzedSha":"01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a","analyzedAt":"2026-09-02T19:38:29.671Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}