{"record":{"id":"0e2196c9c18b1d4e","repo":"benbjohnson/litestream","slug":"cannot-restore-output-path-already-exists-s","errorCode":null,"errorMessage":"cannot restore, output path already exists: %s","messagePattern":"cannot restore, output path already exists: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"replica.go","lineNumber":667,"sourceCode":"\t\t\t_ = snapshotItr.Close()\n\n\t\t\tif latestSnapshot != nil {\n\t\t\t\tif latestSnapshot.MinTXID > txid {\n\t\t\t\t\treturn fmt.Errorf(\"cannot resume follow mode: saved TXID %s is behind the earliest snapshot (min TXID %s); replica history has been pruned -- delete %s and %s-txid to re-restore\", txid, latestSnapshot.MinTXID, opt.OutputPath, opt.OutputPath)\n\t\t\t\t}\n\t\t\t\tif txid > latestSnapshot.MaxTXID {\n\t\t\t\t\treturn fmt.Errorf(\"cannot resume follow mode: saved TXID %s is ahead of latest snapshot (max TXID %s); delete %s and %s-txid to re-restore\", txid, latestSnapshot.MaxTXID, opt.OutputPath, opt.OutputPath)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tr.Logger().Info(\"resuming follow mode from crash recovery\", \"txid\", txid, \"output\", opt.OutputPath)\n\t\t\treturn r.follow(ctx, opt.OutputPath, txid, opt.FollowInterval)\n\t\t}\n\t}\n\n\t// Ensure output path does not already exist.\n\tif _, err := os.Stat(opt.OutputPath); err == nil {\n\t\treturn fmt.Errorf(\"cannot restore, output path already exists: %s\", opt.OutputPath)\n\t} else if !os.IsNotExist(err) {\n\t\treturn err\n\t}\n\n\t// Compare v0.3.x and LTX formats to find the best backup (unless TXID is specified).\n\t// Skip V3 format when follow mode is enabled (V3 doesn't support incremental following).\n\tif opt.TXID == 0 && !opt.Follow {\n\t\tif client, ok := r.Client.(ReplicaClientV3); ok {\n\t\t\tuseV3, err := r.shouldUseV3Restore(ctx, client, opt.Timestamp)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tif useV3 {\n\t\t\t\treturn r.RestoreV3(ctx, opt)\n\t\t\t}\n\t\t}\n\t}\n","sourceCodeStart":649,"sourceCodeEnd":685,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/replica.go#L649-L685","documentation":"Restore refuses to overwrite: the output path already exists and neither follow mode (which supports crash-recovery resume) nor an explicit overwrite option is set. Restoring over an existing file could destroy data.","triggerScenarios":"Thrown at replica.go:667 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Move or delete the existing file first","Restore to a different output path","Use follow mode if resuming an interrupted restore"],"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-14T05:17:10.506Z"}