BuildError.forElement constructor

BuildError.forElement(
  1. Element context,
  2. String message
)

Creates a build error using the provided source element as context.

Implementation

factory BuildError.forElement(
  Element context,
  String message,
) {
  final source = context.source;
  if (source == null || source.contents.data.isEmpty) {
    final warning = source == null
        ? 'No source text available for $context'
        : 'No source text available for $context (${source.uri})';
    log.warning('$warning: the next error may be terse');
    return BuildError.withoutContext(message);
  }
  return BuildError.forSourceSpan(
    spanForElement(context),
    message,
  );
}