urfave/cli · error

got nil/empty layouts slice

Error message

got nil/empty layouts slice

What it means

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.

Source

Thrown at flag_timestamp.go:63

		return ""
	}
	t.timestamp = &b
	return t.String()
}

// Below functions are to satisfy the Value interface

// Parses the string value to timestamp
func (t *timestampValue) Set(value string) error {
	var timestamp time.Time
	var err error

	if t.location == nil {
		t.location = time.UTC
	}

	if len(t.layouts) == 0 {
		return errors.New("got nil/empty layouts slice")
	}

	for _, layout := range t.layouts {
		var locErr error

		timestamp, locErr = time.ParseInLocation(layout, value, t.location)
		if locErr != nil {
			if err == nil {
				err = locErr
				continue
			}

			err = newMultiError(err, locErr)
			continue
		}

		err = nil
		break

View on GitHub (pinned to 1a4deb4f5a)

Solutions

  1. 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.
  2. Ensure the configured time.Time location/config used to build the flag actually passes the layouts through.
  3. If constructing timestampValue manually, pass a non-empty layouts slice.

Example fix

// before
&cli.TimestampFlag{Name: "start"}
// after
&cli.TimestampFlag{Name: "start", Layout: "2006-01-02 15:04:05"}
Defensive patterns

Strategy: validation

Validate before calling

func timestampFlagOK(f *cli.TimestampFlag) bool {
	return f != nil && (f.Layout != "" || len(f.Layouts) > 0)
}
// check before running the command

Try / catch

if err := cmd.Run(ctx, os.Args); err != nil {
	if strings.Contains(err.Error(), "got nil/empty layouts slice") {
		return fmt.Errorf("timestamp flag misconfigured: set Layout on the TimestampFlag")
	}
	return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of urfave/cli@1a4deb4f5a (2026-08-31). Data as JSON: /api/errors/8e1571abcc515f64. Report an issue: GitHub.