Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions internal/turso/tursoServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ func (i *TursoServerClient) Export(outputFile string, withMetadata bool, remoteE
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return parseResponseError(res)
return parseExportResponseError(res)
}
var info ExportInfo
if err := json.NewDecoder(res.Body).Decode(&info); err != nil {
Expand All @@ -472,7 +472,7 @@ func (i *TursoServerClient) Export(outputFile string, withMetadata bool, remoteE
}
defer exportRes.Body.Close()
if exportRes.StatusCode != http.StatusOK {
return parseResponseError(exportRes)
return parseExportResponseError(exportRes)
}

out, err := os.Create(outputFile)
Expand All @@ -497,6 +497,13 @@ func (i *TursoServerClient) Export(outputFile string, withMetadata bool, remoteE
return nil
}

func parseExportResponseError(res *http.Response) error {
if res.StatusCode == http.StatusNotFound {
return errors.New("database export is not available for this database. If this is a Fly-hosted database, use `turso db shell <database> .dump` to create a SQL dump instead")
}
return parseResponseError(res)
}

func (i *TursoServerClient) ExportWAL(outputFile string, info *ExportInfo, remoteEncryptionKey string) (int, error) {
walFile := outputFile + "-wal"
walOut, err := os.Create(walFile)
Expand Down
16 changes: 16 additions & 0 deletions internal/turso/tursoServer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,22 @@ func TestUploadFileMultipart_SmoothProgress(t *testing.T) {
require.True(t, calls[len(calls)-1].Done, "Final callback should have Done=true")
}

func TestExportReportsUnsupportedDatabaseForNotFound(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
require.Equal(t, "/info", r.URL.Path)
w.WriteHeader(http.StatusNotFound)
}))
defer server.Close()

client := createTestClient(t, server.URL)
err := client.Export("unused.db", false, "")

require.Error(t, err)
require.Contains(t, err.Error(), "database export is not available")
require.Contains(t, err.Error(), "Fly-hosted database")
require.NotContains(t, err.Error(), "response failed with status 404 Not Found")
}

// infiniteReader provides unlimited bytes for large file simulation (never returns EOF)
type infiniteReader struct {
bytesRead int64
Expand Down
Loading