Skip to content

Commit 5a0ed40

Browse files
committed
db unarchive: suggest the group unarchive command when applicable
When a user runs turso db unarchive on a database that's part of a group, the server returns "database X is part of a group, please unarchive the group instead" but doesn't tell them how. Look up the database's group on that specific failure path and append the exact command (`turso group unarchive <group>`) to the error message, matching the pattern db_replicate already uses. Falls back to the bare server error when the lookup fails. Closes #918. Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
1 parent 2e8610c commit 5a0ed40

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

internal/cmd/db_wakeup.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"fmt"
5+
"strings"
56
"time"
67

78
"github.com/spf13/cobra"
@@ -38,6 +39,16 @@ func wakeupDatabase(client *turso.Client, name string) error {
3839
defer s.Stop()
3940

4041
if err := client.Databases.Wakeup(name); err != nil {
42+
// If the database is part of a group the server tells us so
43+
// but doesn't tell the user what to run instead. Look up the
44+
// database to grab its group and suggest the right command.
45+
// See #918.
46+
if strings.Contains(err.Error(), "part of a group") {
47+
if db, lookupErr := client.Databases.Get(name); lookupErr == nil && db.Group != "" {
48+
cmd := internal.Emph(fmt.Sprintf("turso group unarchive %s", db.Group))
49+
return fmt.Errorf("%w. Run %s instead", err, cmd)
50+
}
51+
}
4152
return err
4253
}
4354
s.Stop()

0 commit comments

Comments
 (0)