benbjohnson/litestream · error

too many arguments

Error message

too many arguments

What it means

`litestream stop` accepts exactly one positional argument — the database path — after flag parsing. Supplying more than one triggers this plain 'too many arguments' error from the CLI argument validation in StopCommand.Run.

Source

Thrown at cmd/litestream/stop.go:38

// Run executes the stop command.
func (c *StopCommand) Run(ctx context.Context, args []string) error {
	fs := flag.NewFlagSet("litestream-stop", flag.ContinueOnError)
	timeout := fs.Int("timeout", 30, "timeout in seconds")
	socketPath := fs.String("socket", "/var/run/litestream.sock", "control socket path")
	jsonOutput := fs.Bool("json", false, "output raw JSON")
	fs.Usage = c.Usage
	if err := fs.Parse(args); err != nil {
		return err
	}

	if fs.NArg() == 0 {
		return &usageError{
			message: "database path required",
			hint:    "litestream stop /path/to/db",
		}
	}
	if fs.NArg() > 1 {
		return fmt.Errorf("too many arguments")
	}

	dbPath := fs.Arg(0)

	// Create HTTP client that connects via Unix socket with timeout
	clientTimeout := time.Duration(*timeout) * time.Second
	client := &http.Client{
		Timeout: clientTimeout,
		Transport: &http.Transport{
			DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
				return net.DialTimeout("unix", *socketPath, clientTimeout)
			},
		},
	}

	req := litestream.StopRequest{
		Path:    dbPath,
		Timeout: *timeout,

View on GitHub (pinned to 4ed7a308f6)

Solutions

  1. Pass exactly one database path: litestream stop /path/to/db
  2. Stop multiple databases by running the command once per DB
  3. Quote the path so spaces don't split it into two arguments
  4. Run `litestream stop -h` to review usage

Example fix

// before
litestream stop /data/app.db /data/analytics.db
// after
litestream stop /data/app.db
litestream stop /data/analytics.db
Defensive patterns

Strategy: validation

Validate before calling

args_count=$(nth_arg_count "$@")  # ensure exactly one positional after flags
[ $# -gt 0 ] && [ "$#" -le 1 ] || { echo 'usage: litestream stop DB_PATH'; exit 64; }

Prevention

When it happens

Trigger: Running e.g. `litestream stop /db1 /db2` or `litestream stop db1 db2` — any invocation where flagset NArg() exceeds 1.

Common situations: Users assuming stop takes multiple databases or glob patterns like `litestream stop /data/*.db`; scripts passing extra positional params; forgetting that flags must come before the DB path.

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 benbjohnson/litestream@4ed7a308f6 (2026-09-06). Data as JSON: /api/errors/ad893acce59a31df. Report an issue: GitHub.