{"record":{"id":"9409735768e515f6","repo":"benbjohnson/litestream","slug":"l0-retention-must-not-be-negative","errorCode":null,"errorMessage":"l0 retention must not be negative","messagePattern":"l0 retention must not be negative","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream/main.go","lineNumber":57,"sourceCode":"// Version is set via -ldflags \"-X main.Version=...\" on release and Makefile\n// builds; otherwise it is resolved from embedded VCS build info at startup.\nvar Version = defaultVersion\n\nfunc init() {\n\tbi, _ := debug.ReadBuildInfo()\n\tVersion = resolveVersion(Version, bi)\n}\n\n// errStop is a terminal error for indicating program should quit.\nvar errStop = errors.New(\"stop\")\n\n// Sentinel errors for configuration validation\nvar (\n\tErrInvalidSnapshotInterval         = errors.New(\"snapshot interval must be greater than 0\")\n\tErrInvalidSnapshotRetention        = errors.New(\"snapshot retention must be greater than 0\")\n\tErrInvalidCompactionInterval       = errors.New(\"compaction interval must be greater than 0\")\n\tErrInvalidSyncInterval             = errors.New(\"sync interval must be greater than 0\")\n\tErrInvalidL0Retention              = errors.New(\"l0 retention must not be negative\")\n\tErrInvalidL0RetentionCheckInterval = errors.New(\"l0 retention check interval must be greater than 0\")\n\tErrInvalidShutdownSyncTimeout      = errors.New(\"shutdown-sync-timeout must be >= 0\")\n\tErrInvalidShutdownSyncInterval     = errors.New(\"shutdown sync interval must be greater than 0\")\n\tErrInvalidHeartbeatURL             = errors.New(\"heartbeat URL must be a valid HTTP or HTTPS URL\")\n\tErrInvalidHeartbeatInterval        = errors.New(\"heartbeat interval must be at least 1 minute\")\n\tErrConfigFileNotFound              = errors.New(\"config file not found\")\n)\n\n// ConfigValidationError wraps a validation error with additional context\ntype ConfigValidationError struct {\n\tErr   error\n\tField string\n\tValue interface{}\n}\n\nfunc (e *ConfigValidationError) Error() string {\n\tif e.Value != nil {\n\t\treturn fmt.Sprintf(\"%s: %v (got %v)\", e.Field, e.Err, e.Value)","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream/main.go#L39-L75","documentation":"Sentinel error ErrInvalidL0Retention is returned by Config.Validate when l0-retention is configured with a negative value. Unlike most intervals, zero is allowed for L0 retention (meaning effectively no retention), but a negative duration is nonsensical and rejected. Wrapped in ConfigValidationError with Field \"l0-retention\".","triggerScenarios":"Setting l0-retention to a negative duration in the top-level config (e.g. l0-retention: \"-5m\") and running Validate.","commonSituations":"Sign typo when writing the duration; a computed value where a subtraction went negative; misreading docs that allow 0 but not negatives.","solutions":["Set l0-retention to a non-negative duration (0 is permitted, e.g. \"24h\" for a day of L0 retention).","If you wanted to disable L0 retention, use 0 rather than a negative value.","Check for arithmetic or sign errors in whatever computes the value."],"exampleFix":"# before\nl0-retention: -5m\n# after\nl0-retention: 24h","handlingStrategy":"validation","validationCode":"if cfg.L0Retention != nil && *cfg.L0Retention < 0 {\n    return errors.New(\"l0-retention must be >= 0\")\n}","typeGuard":null,"tryCatchPattern":"if err := cfg.Validate(); err != nil {\n    var ve *main.ConfigValidationError\n    if errors.As(err, &ve) && errors.Is(ve.Err, main.ErrInvalidL0Retention) {\n        return fmt.Errorf(\"l0-retention %v is negative\", ve.Value)\n    }\n    return err\n}","preventionTips":["Remember 0 is legal for l0-retention; only negatives fail — use 0 to disable.","Double-check signs when computing retention durations programmatically.","Validate configs before deployment."],"tags":["go","configuration","validation","retention"],"backgroundTag":"invalid-config-value","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"}