{"record":{"id":"d3d59d5a9c458d25","repo":"benbjohnson/litestream","slug":"cannot-create-replica-for-restore-w","errorCode":null,"errorMessage":"cannot create replica for restore: %w","messagePattern":"cannot create replica for restore: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream/replicate.go","lineNumber":498,"sourceCode":"\tif _, err := os.Stat(dbPath); !os.IsNotExist(err) {\n\t\tslog.Info(\"database exists, skipping restore\", \"path\", dbPath)\n\t\treturn nil\n\t}\n\n\t// Get replica config (handles both Replica and Replicas fields)\n\tvar rc *ReplicaConfig\n\tif dbConfig.Replica != nil {\n\t\trc = dbConfig.Replica\n\t} else if len(dbConfig.Replicas) > 0 {\n\t\trc = dbConfig.Replicas[0]\n\t} else {\n\t\treturn fmt.Errorf(\"no replica configured for database: %s\", dbPath)\n\t}\n\n\t// Create replica from config (nil db since we're just restoring)\n\tr, err := NewReplicaFromConfig(rc, nil)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot create replica for restore: %w\", err)\n\t}\n\n\t// Attempt restore\n\topt := litestream.NewRestoreOptions()\n\topt.OutputPath = dbPath\n\n\tslog.Info(\"attempting restore before replication\", \"path\", dbPath)\n\tif err := r.Restore(ctx, opt); errors.Is(err, litestream.ErrTxNotAvailable) {\n\t\t// No backup exists yet (first start) - this is OK\n\t\tslog.Info(\"no backup found, starting fresh\", \"path\", dbPath)\n\t\treturn nil\n\t} else if err != nil {\n\t\treturn fmt.Errorf(\"restore failed: %w\", err)\n\t}\n\n\tslog.Info(\"restore completed\", \"path\", dbPath)\n\treturn nil\n}","sourceCodeStart":480,"sourceCodeEnd":516,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream/replicate.go#L480-L516","documentation":"NewReplicaFromConfig failed while building the replica client used for the initial restore in restoreIfNeeded. The replica config itself is invalid — bad URL, mutually exclusive fields, or missing required settings such as bucket.","triggerScenarios":"Thrown at cmd/litestream/replicate.go:498 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix the underlying replica config error reported by the wrapped error","Validate the replica URL format and required fields"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}