{"record":{"id":"8e1571abcc515f64","repo":"urfave/cli","slug":"got-nil-empty-layouts-slice","errorCode":null,"errorMessage":"got nil/empty layouts slice","messagePattern":"got nil/empty layouts slice","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"flag_timestamp.go","lineNumber":63,"sourceCode":"\t\treturn \"\"\n\t}\n\tt.timestamp = &b\n\treturn t.String()\n}\n\n// Below functions are to satisfy the Value interface\n\n// Parses the string value to timestamp\nfunc (t *timestampValue) Set(value string) error {\n\tvar timestamp time.Time\n\tvar err error\n\n\tif t.location == nil {\n\t\tt.location = time.UTC\n\t}\n\n\tif len(t.layouts) == 0 {\n\t\treturn errors.New(\"got nil/empty layouts slice\")\n\t}\n\n\tfor _, layout := range t.layouts {\n\t\tvar locErr error\n\n\t\ttimestamp, locErr = time.ParseInLocation(layout, value, t.location)\n\t\tif locErr != nil {\n\t\t\tif err == nil {\n\t\t\t\terr = locErr\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\terr = newMultiError(err, locErr)\n\t\t\tcontinue\n\t\t}\n\n\t\terr = nil\n\t\tbreak","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/urfave/cli/blob/1a4deb4f5a35ee12706602698dc0527d44c14b19/flag_timestamp.go#L45-L81","documentation":"This error is returned by (*timestampValue).Set when the timestamp flag was configured with no time layouts (formats). time.ParseInLocation needs at least one layout string to know how to interpret the input, so an empty layouts slice is a configuration bug in the flag definition, not bad user input.","triggerScenarios":"Creating a timestamp flag (e.g. via TimestampFlag with no TimestampLayout, or a timestampValue built with a nil/empty layouts slice) and then calling Set with any value. The check runs before parsing, so every Set call on such a flag fails.","commonSituations":"Upgrading urfave/cli where timestamp flag configuration fields changed (older single Layout field vs newer layouts slice), or hand-constructing a TimestampFlag and forgetting to set the layout.","solutions":["Set the layout(s) on the flag, e.g. TimestampFlag{Layout: \"2006-01-02\"} or the equivalent Layouts field with one or more Go time layouts.","Ensure the configured time.Time location/config used to build the flag actually passes the layouts through.","If constructing timestampValue manually, pass a non-empty layouts slice."],"exampleFix":"// before\n&cli.TimestampFlag{Name: \"start\"}\n// after\n&cli.TimestampFlag{Name: \"start\", Layout: \"2006-01-02 15:04:05\"}","handlingStrategy":"validation","validationCode":"func timestampFlagOK(f *cli.TimestampFlag) bool {\n\treturn f != nil && (f.Layout != \"\" || len(f.Layouts) > 0)\n}\n// check before running the command","typeGuard":null,"tryCatchPattern":"if err := cmd.Run(ctx, os.Args); err != nil {\n\tif strings.Contains(err.Error(), \"got nil/empty layouts slice\") {\n\t\treturn fmt.Errorf(\"timestamp flag misconfigured: set Layout on the TimestampFlag\")\n\t}\n\treturn err\n}","preventionTips":["Always set Layout (or Layouts) when declaring a TimestampFlag.","After library upgrades, verify timestamp flag field names/semantics still match your usage.","Unit-test command construction so a layout-less timestamp flag fails in tests, not in production."],"tags":["go","flag-parsing","timestamp","configuration"],"backgroundTag":"missing-flag-configuration","analyzedSha":"1a4deb4f5a35ee12706602698dc0527d44c14b19","analyzedAt":"2026-08-31T18:42:09.451Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}