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