onQueryError method

  1. @override
void onQueryError(
  1. QueryErrorEvent event
)
override

Called when a query fails.

Implementation

@override
void onQueryError(QueryErrorEvent event) {
  final buffer = StringBuffer();

  final errorColor = colorize ? '\x1B[31m' : ''; // Red
  final reset = colorize ? '\x1B[0m' : '';

  if (event.operation != null) {
    final op = event.operation;
    buffer.write('[$op] ');
  }

  buffer.write('$errorColor[ERROR]$reset ');
  buffer.write('[${event.duration.inMilliseconds}ms] ');
  buffer.write(event.error);

  if (includeSql) {
    buffer.write('\n  SQL: ${_truncateSql(event.sql)}');
  }

  if (includeParameters && event.parameters.isNotEmpty) {
    buffer.write('\n  Params: ${_sanitizeParams(event.parameters)}');
  }

  print(buffer.toString());
}