benbjohnson/litestream · error

invalid level: must be 0-%d or "all"

Error message

invalid level: must be 0-%d or "all"

What it means

levelVar.Set implements flag.Value for the `litestream ltx -level` flag. If the argument is not the literal "all" and cannot be parsed as an integer, it reports that the level must be 0 through SnapshotLevel or "all".

Source

Thrown at cmd/litestream/main.go:2201

type levelVar int

var _ flag.Value = (*levelVar)(nil)

func (v *levelVar) String() string {
	if *v == levelAll {
		return "all"
	}
	return strconv.Itoa(int(*v))
}

func (v *levelVar) Set(s string) error {
	if s == "all" {
		*v = levelAll
		return nil
	}
	n, err := strconv.Atoi(s)
	if err != nil {
		return fmt.Errorf("invalid level: must be 0-%d or \"all\"", litestream.SnapshotLevel)
	}
	if n < 0 || n > litestream.SnapshotLevel {
		return fmt.Errorf("level must be between 0 and %d", litestream.SnapshotLevel)
	}
	*v = levelVar(n)
	return nil
}

View on GitHub (pinned to 4ed7a308f6)

Solutions

  1. Pass a plain integer between 0 and the max snapshot level (e.g. `-level 2`).
  2. Use `-level all` (lowercase) to show every compaction level.
  3. Run `litestream ltx -h` to confirm the accepted range shown in the flag usage.

Example fix

// before
litestream ltx -level snapshot
// after
litestream ltx -level all
Defensive patterns

Strategy: validation

Validate before calling

// Accept only ints or the literal "all" before invoking the CLI
if level != "all" {
    if _, err := strconv.Atoi(level); err != nil {
        return fmt.Errorf("-level must be an integer or 'all'")
    }
}

Try / catch

if err := cmd.Run(); err != nil {
    if strings.Contains(err.Error(), "invalid level") {
        // fall back to -level all
    }
}

Prevention

When it happens

Trigger: Running `litestream ltx -level snapshot` or `-level 0,1,2` or `-level ALL` (case-sensitive) — anything non-numeric and not exactly `all`.

Common situations: Assuming named levels like `snapshot` or `wal` are accepted; passing comma-separated lists; shell-cased `All` instead of lowercase `all`.

Understand the failure class

Background: "unknown output mode", "invalid value for flag", "expects true/false": fixing invalid flag value errors in CLI tools — this error's family across 24 libraries.

Related errors


AI-assisted analysis of benbjohnson/litestream@4ed7a308f6 (2026-09-06). Data as JSON: /api/errors/512e6b1691f93a63. Report an issue: GitHub.