{"record":{"id":"0273f4b14d0d70fa","repo":"benbjohnson/litestream","slug":"validate-level-d-for-s-w","errorCode":null,"errorMessage":"validate level %d for %s: %w","messagePattern":"validate level (.+?) for (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"store.go","lineNumber":881,"sourceCode":"// Validate checks LTX file consistency across all databases and levels.\n// SnapshotLevel (9) is excluded since snapshots are not contiguous.\nfunc (s *Store) Validate(ctx context.Context) (*ValidationResult, error) {\n\tresult := &ValidationResult{Valid: true}\n\n\ts.mu.Lock()\n\tdbs := s.dbs\n\tlevels := s.levels\n\ts.mu.Unlock()\n\n\tfor _, db := range dbs {\n\t\tif db.Replica == nil {\n\t\t\tcontinue\n\t\t}\n\n\t\tfor _, lvl := range levels {\n\t\t\terrs, err := db.Replica.ValidateLevel(ctx, lvl.Level)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"validate level %d for %s: %w\", lvl.Level, db.Path(), err)\n\t\t\t}\n\t\t\tif len(errs) > 0 {\n\t\t\t\tresult.Valid = false\n\t\t\t\tresult.Errors = append(result.Errors, errs...)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn result, nil\n}\n\n// monitorValidation periodically runs validation checks on all databases.\nfunc (s *Store) monitorValidation(ctx context.Context) {\n\ts.Logger.Info(\"starting validation monitor\", \"interval\", s.ValidationInterval)\n\n\tticker := time.NewTicker(s.ValidationInterval)\n\tdefer ticker.Stop()\n","sourceCodeStart":863,"sourceCodeEnd":899,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/store.go#L863-L899","documentation":"Store.Validate failed while db.Replica.ValidateLevel(ctx, lvl.Level) fetched the LTX file listing for a level from replica storage. ValidateLevel performs integrity checks across a level's files; the error here means the listing itself could not be retrieved (as opposed to validation findings, which are returned in result.Errors). The wrapped error includes the level and database path.","triggerScenarios":"Validate(ctx) / monitorValidation iterating levels for each DB where Client.LTXFiles(ctx, level, ...) fails: auth failure, network error, missing bucket/prefix, or context timeout during enumeration.","commonSituations":"Storage credentials rotated or revoked before a scheduled validation run, bucket deleted or renamed, network partition, or provider throttling during large listings.","solutions":["Read the wrapped error from ValidateLevel (\"fetch ltx files: %w\") for the storage-specific cause and fix credentials/bucket config.","Verify the replica storage location still exists and contains the expected level structure.","Re-run litestream validate (or wait for the next monitorValidation cycle) after restoring storage access.","Check context timeouts if validation runs against slow or remote storage."],"exampleFix":"// before\nerrs, err := db.Replica.ValidateLevel(ctx, lvl.Level)\nif err != nil {\n    return nil, fmt.Errorf(\"validate level %d for %s: %w\", lvl.Level, db.Path(), err)\n}\n// after\nerrs, err := db.Replica.ValidateLevel(ctx, lvl.Level)\nif err != nil {\n    if ctx.Err() != nil {\n        return nil, fmt.Errorf(\"validation canceled: %w\", ctx.Err())\n    }\n    return nil, fmt.Errorf(\"validate level %d for %s: %w\", lvl.Level, db.Path(), err)\n}","handlingStrategy":"retry","validationCode":"ctx, cancel := context.WithTimeout(ctx, 10*time.Minute)\ndefer cancel()\nitr, err := client.LTXFiles(ctx, level, 0, false)\nif err != nil {\n    return fmt.Errorf(\"level %d not listable before validate: %w\", level, err)\n}\nitr.Close()","typeGuard":null,"tryCatchPattern":"results, err := store.Validate(ctx)\nif err != nil {\n    if errors.Is(err, context.DeadlineExceeded) || isStorageTransient(err) {\n        log.Printf(\"validation deferred; will retry next cycle\")\n        return nil\n    }\n    return err\n}","preventionTips":["Verify bucket/prefix existence after any storage migration","Rotate credentials proactively so validation runs never hit expired keys","Allow generous timeouts for validating large levels","Distinguish validation FINDINGS (returned in errors list) from fetch errors before alerting"],"tags":["go","litestream","validation","storage"],"backgroundTag":"http-request-failed","analyzedSha":"4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3","analyzedAt":"2026-09-06T18:29:25.564Z","contentChangedAt":"2026-09-06T18:29:25.564Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}