ory/kratos · error

expected zero or two args, got

Error message

expected zero or two args, got %d: %+v

What it means

The ory identities list CLI command accepts either no positional arguments (list all) or exactly two (page token and size legacy style). Any other argument count causes cobra's Args validator to fail with this message before RunE executes.

Solutions

  1. Run with zero positional args and use flags: ory identities list --page-size 100
  2. If paging manually, pass exactly two args (page size and page token) or better use the flags
  3. Use ory identities list --help to confirm the accepted argument shape for your CLI version

Example fix

// before
ory list identities 100
// after
ory list identities --page-size 100
// or legacy two-arg form
ory list identities 100 <page-token>
Defensive patterns

Strategy: validation

Validate before calling

// shell
if [ $# -ne 0 ] && [ $# -ne 2 ]; then echo "usage: ory identities list [--page-size N]"; exit 1; fi

Prevention

When it happens

Trigger: Running `ory list identities extra-arg` with one or more than two positional args, e.g. passing a single filter value or extra flags-like tokens positionally.

Common situations: Users pass a single positional 'page size' or an identifier expecting filtering; shell scripts append variables that expand to an unexpected count; confusion with older CLI versions that accepted different arity.

Understand the failure class

Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.

Related errors


AI-assisted analysis of ory/kratos@b86338da04 (2026-09-07). Data as JSON: /api/errors/45d915d5990612a3. Report an issue: GitHub.

Appendix: source

Thrown at cmd/identities/list.go:43

	c.AddCommand(NewListIdentitiesCmd())
	cliclient.RegisterClientFlags(c.PersistentFlags())
	cmdx.RegisterFormatFlags(c.PersistentFlags())
	return c
}

func NewListIdentitiesCmd() *cobra.Command {
	c := &cobra.Command{
		Use:   "identities",
		Short: "List identities",
		Long: `Return a list of identities.

The consistency defaults to ` + "`eventual`" + ` and can be set to ` + "`strong`" + ` or ` + "`eventual`" + `.
Eventual consistency means that the list operation will return faster and might not include recently created or updated identities. Replication lag is about 5 seconds.`,
		Example: "{{ .CommandPath }} --page-size 100 --consistency eventual",
		Args: func(cmd *cobra.Command, args []string) error {
			// zero or exactly two args
			if len(args) != 0 && len(args) != 2 {
				return fmt.Errorf("expected zero or two args, got %d: %+v", len(args), args)
			}
			return nil
		},
		RunE: func(cmd *cobra.Command, args []string) error {
			c, err := cliclient.NewClient(cmd)
			if err != nil {
				return err
			}

			consistency := flagx.MustGetString(cmd, "consistency")
			req := c.IdentityAPI.ListIdentities(cmd.Context()).Consistency(consistency)
			page, perPage, err := cmdx.ParseTokenPaginationArgs(cmd)
			if err != nil {
				return err
			}

			req = req.PageToken(page)
			req = req.PageSize(int64(perPage))

View on GitHub (pinned to b86338da04)