@t1mmen/srtd
Version:
Supabase Repeatable Template Definitions (srtd): 🪄 Live-reloading SQL templates for Supabase DX. Make your database changes reviewable and migrations maintainable! 🚀
50 lines • 1.81 kB
JavaScript
import chalk from 'chalk';
import figures from 'figures';
import { formatPath } from '../utils/formatPath.js';
import { SEPARATOR } from './constants.js';
import { renderErrorContext } from './errorContext.js';
/**
* Renders the error display with SQL context and color coding.
*
* Format:
* ERRORS
* ─────────────────────────────────────────────────────
* X .../views/broken.sql
* | syntax error at line 5:
* | CREATE OR REPLACE FUNCTION broken_func(
* | ^ expected parameter
* ─────────────────────────────────────────────────────
*/
export function renderErrorDisplay(options) {
const { errors } = options;
if (errors.length === 0) {
return;
}
// Header
console.log(chalk.red.bold('ERRORS'));
console.log(chalk.dim(SEPARATOR));
// Render each error
for (const error of errors) {
renderError(error);
console.log(); // Blank line between errors
}
// Footer
console.log(chalk.dim(SEPARATOR));
}
/**
* Renders a single error item with optional SQL context.
*/
function renderError(error) {
const templateName = formatPath.ensureSqlExtension(error.template);
// Error header: X template.sql
console.log(chalk.red(`${figures.cross} ${templateName}`));
// Error context: message, SQL snippet, caret, hint
renderErrorContext({
message: error.message,
hint: error.hint,
sqlSnippet: error.sqlSnippet,
column: error.column,
indentPrefix: ' ', // 2 spaces for errorDisplay
});
}
//# sourceMappingURL=errorDisplay.js.map