Skip to content

Commit 9b9b5a2

Browse files
authored
fix: better suggestions on pg connection error (#4597)
* fix: better suggestions on pg connection error * chore: use project specific url * chore: resolve conflict
1 parent 358a5ff commit 9b9b5a2

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

internal/utils/connect.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,22 @@ func ConnectByUrl(ctx context.Context, url string, options ...func(*pgx.ConnConf
164164
}
165165
cc.Fallbacks = fallbacks
166166
})
167-
return pgxv5.Connect(ctx, url, options...)
167+
conn, err := pgxv5.Connect(ctx, url, options...)
168+
var pgErr *pgconn.PgError
169+
if errors.As(err, &pgErr) {
170+
if strings.Contains(pgErr.Message, "connect: connection refused") {
171+
CmdSuggestion = fmt.Sprintf("Make sure your local IP is allowed in Network Restrictions and Network Bans.\n%s/project/_/database/settings", CurrentProfile.DashboardURL)
172+
} else if strings.Contains(pgErr.Message, "SSL connection is required") && viper.GetBool("DEBUG") {
173+
CmdSuggestion = "SSL connection is not supported with --debug flag"
174+
} else if strings.Contains(pgErr.Message, "SCRAM exchange: Wrong password") || strings.Contains(pgErr.Message, "failed SASL auth") {
175+
// password authentication failed for user / invalid SCRAM server-final-message received from server
176+
CmdSuggestion = "Try setting the SUPABASE_DB_PASSWORD environment variable"
177+
} else if strings.Contains(pgErr.Message, "connect: no route to host") || strings.Contains(pgErr.Message, "Tenant or user not found") {
178+
// Assumes IPv6 check has been performed before this
179+
CmdSuggestion = "Make sure your project exists on profile: " + CurrentProfile.Name
180+
}
181+
}
182+
return conn, err
168183
}
169184

170185
const (

0 commit comments

Comments
 (0)