{"record":{"id":"ff9b0d34dbe0f12f","repo":"benbjohnson/litestream","slug":"level-must-be-between-0-and-d","errorCode":null,"errorMessage":"level must be between 0 and %d","messagePattern":"level must be between 0 and (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream/main.go","lineNumber":2204,"sourceCode":"\nfunc (v *levelVar) String() string {\n\tif *v == levelAll {\n\t\treturn \"all\"\n\t}\n\treturn strconv.Itoa(int(*v))\n}\n\nfunc (v *levelVar) Set(s string) error {\n\tif s == \"all\" {\n\t\t*v = levelAll\n\t\treturn nil\n\t}\n\tn, err := strconv.Atoi(s)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"invalid level: must be 0-%d or \\\"all\\\"\", litestream.SnapshotLevel)\n\t}\n\tif n < 0 || n > litestream.SnapshotLevel {\n\t\treturn fmt.Errorf(\"level must be between 0 and %d\", litestream.SnapshotLevel)\n\t}\n\t*v = levelVar(n)\n\treturn nil\n}\n","sourceCodeStart":2186,"sourceCodeEnd":2209,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream/main.go#L2186-L2209","documentation":"levelVar.Set rejected a numeric level flag because it falls outside the valid compaction level range 0..litestream.SnapshotLevel. Levels below 0 or above the snapshot level do not exist in the LTX level scheme.","triggerScenarios":"Running `litestream ltx -level 10` (or any integer > SnapshotLevel) or `-level -1`.","commonSituations":"Guessing the max compaction level after Litestream changed its level set; copying a `-level` value from older docs or other tools.","solutions":["Use a level between 0 and litestream.SnapshotLevel (see `litestream ltx -h` for the exact max).","Use `-level all` when you want every level rather than enumerating high numbers.","Check docs/LTX_FORMAT.md or the level list printed by the command for valid levels."],"exampleFix":"// before\nlitestream ltx -level 10\n// after\nlitestream ltx -level 3","handlingStrategy":"validation","validationCode":"// Clamp level into valid range before invoking the CLI\nn, _ := strconv.Atoi(level)\nif n < 0 || n > maxSnapshotLevel {\n    n = maxSnapshotLevel\n}","typeGuard":null,"tryCatchPattern":"if err := cmd.Run(); err != nil {\n    if strings.Contains(err.Error(), \"level must be between\") {\n        // retry with -level all or a clamped value\n    }\n}","preventionTips":["Clamp scripted -level values to 0..SnapshotLevel.","Prefer `-level all` over hardcoding high level numbers in scripts."],"tags":["cli","flag-parsing","range","ltx"],"backgroundTag":"value-out-of-range","analyzedSha":"4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3","analyzedAt":"2026-09-06T18:29:25.564Z","contentChangedAt":"2026-09-06T18:29:25.564Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}