openimsdk/open-im-server · error

no command to run

Error message

no command to run

What it means

cmds.run validates that at least one subcommand was registered before doing any initialization. If x.cmds is empty there is nothing to execute, so it aborts immediately with this error. It is a startup-time guard, not a runtime fault.

Source

Thrown at cmd/main.go:260

		"", "",
		conf.RemainLogLevel,
		conf.IsStdout,
		conf.IsJson,
		conf.StorageLocation,
		conf.RemainRotationCount,
		conf.RotationTime,
		strings.TrimSpace(version.Version),
		conf.IsSimplify,
	); err != nil {
		return err
	}
	return nil

}

func (x *cmds) run(ctx context.Context) error {
	if len(x.cmds) == 0 {
		return fmt.Errorf("no command to run")
	}
	if err := x.initAllConfig(); err != nil {
		return err
	}
	if err := x.initLog(); err != nil {
		return err
	}

	ctx, cancel := context.WithCancelCause(ctx)

	go func() {
		<-ctx.Done()
		log.ZError(ctx, "context server exit cause", context.Cause(ctx))
	}()

	if prometheus := x.config.API.Prometheus; prometheus.Enable {
		var (
			port int

View on GitHub (pinned to 175a7bb067)

Solutions

  1. Invoke the binary with a valid subcommand/arguments so a command gets registered
  2. Check main.go that cmd.AddCommand(...) (or the equivalent registration) is called for the intended commands
  3. If embedding, call the command-registration API before run() executes

Example fix

// before
./openim-server            # no command -> 'no command to run'
// after
./openim-server --config=config/ start
Defensive patterns

Strategy: validation

Validate before calling

if len(os.Args) < 2 {
	fmt.Fprintln(os.Stderr, "usage: openim-server <command> [flags]")
	os.Exit(2)
}

Prevention

When it happens

Trigger: The binary is invoked without registering any command (e.g. cmd.Execute / cmd.AddCommand never added a runnable command, or the CLI args selected no command) so len(x.cmds)==0 when run() starts.

Common situations: Running the OpenIM server binary with no subcommand (e.g. just ./openim-server instead of ./openim-server --config=... start); a miswired main.go that forgot cmd.AddCommand; a wrapper script passing empty arguments.

Related errors


AI-assisted analysis of openimsdk/open-im-server@175a7bb067 (2026-09-04). Data as JSON: /api/errors/258131d0805257f7. Report an issue: GitHub.