describeFailure function
Turns the output of a failed supabase db query into the message shown
to the user, with dedicated wording for the setup problems the tool can
name. Passwords of connection strings echoed by the CLI are redacted.
Implementation
String describeFailure(String rawOutput, {DatabaseTarget? target}) {
final output = rawOutput
.split('\n')
.where((line) => !line.startsWith('Connecting to '))
.join('\n')
.replaceAllMapped(_connectionStringPassword, (match) => '${match[1]}***@')
.trim();
if (target is LinkedProject &&
target.projectRef != null &&
output.contains('supabase db query [flags]')) {
// CLI releases before 2.116 have no --project-ref on db query and answer
// with the usage text.
return 'This Supabase CLI does not accept --project-ref for db query. '
'Upgrade to 2.116 or newer, or run `supabase link --project-ref '
'${target.projectRef}` and pass --linked instead.';
}
if (output.contains('Access token not provided')) {
return 'The Supabase CLI is not logged in. Run `supabase login`, or set '
'SUPABASE_ACCESS_TOKEN, and try again.';
}
if (output.contains('Cannot find project ref')) {
return 'No linked Supabase project was found. Run `supabase link` in '
'your project directory, or pass --project-ref.';
}
return 'supabase db query failed:\n$output';
}