UtilityTabResults.utils.ts18 lines · main
1/**
2 * Pick which lines to render for a SQL editor error.
3 *
4 * pg-meta returns `formattedError` with multi-line ERROR/HINT/LINE output from Postgres.
5 * Historically only `message` was reliably populated end-to-end, which is why the UI also
6 * falls back to splitting `message` on newlines — e.g. the enhanced permission-denied HINT
7 * added by briven/postgres#2084 arrives in the message body on some paths.
8 *
9 * Returns an empty array when the error is single-line (message only) — callers fall back to
10 * a plain "Error: {message}" rendering in that case.
11 */
12export function getSqlErrorLines(error: { message?: string; formattedError?: string }): string[] {
13 const formattedLines = (error.formattedError?.split('\n') ?? []).filter((x) => x.length > 0)
14 if (formattedLines.length > 0) return formattedLines
15
16 const messageLines = (error.message?.split('\n') ?? []).filter((x) => x.length > 0)
17 return messageLines.length > 1 ? messageLines : []
18}