Improve the error message for a global member conflict (#762)

This commit is contained in:
Natalie Weizenbaum 2019-07-18 01:47:56 +01:00 committed by GitHub
parent c0f51c292a
commit e454647d27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 5 deletions

View File

@ -717,9 +717,11 @@ class AsyncEnvironment {
for (var module in _globalModules) {
var valueInModule = callback(module);
if (valueInModule != null && value != null) {
// TODO(nweiz): List the module URLs.
throw SassScriptException(
'Multiple global modules have a $type named "$name".');
'Multiple global modules have a $type named "$name":\n' +
bulletedList(_globalModules
.where((module) => callback(module) != null)
.map((module) => p.prettyUri(module.url))));
}
value = valueInModule;

View File

@ -5,7 +5,7 @@
// DO NOT EDIT. This file was generated from async_environment.dart.
// See tool/grind/synchronize.dart for details.
//
// Checksum: fe68ec0b099d3f2992af03dbdaeff0b3e8392808
// Checksum: 23da0a0dca141c7ac432dc64958c4240eeceb23d
//
// ignore_for_file: unused_import
@ -722,9 +722,11 @@ class Environment {
for (var module in _globalModules) {
var valueInModule = callback(module);
if (valueInModule != null && value != null) {
// TODO(nweiz): List the module URLs.
throw SassScriptException(
'Multiple global modules have a $type named "$name".');
'Multiple global modules have a $type named "$name":\n' +
bulletedList(_globalModules
.where((module) => callback(module) != null)
.map((module) => p.prettyUri(module.url))));
}
value = valueInModule;

View File

@ -10,6 +10,7 @@ import 'package:charcode/charcode.dart';
import 'package:collection/collection.dart';
import 'package:source_span/source_span.dart';
import 'package:stack_trace/stack_trace.dart';
import 'package:term_glyph/term_glyph.dart' as glyph;
import 'ast/node.dart';
import 'util/character.dart';
@ -38,6 +39,15 @@ String pluralize(String name, int number, {String plural}) {
return '${name}s';
}
/// Returns a bulleted list of items in [bullets].
String bulletedList(Iterable<String> bullets) {
return bullets.map((element) {
var lines = element.split("\n");
return "${glyph.bullet} ${lines.first}" +
(lines.length > 1 ? "\n" + indent(lines.skip(1).join("\n"), 2) : "");
}).join("\n");
}
/// Returns the number of times [codeUnit] appears in [string].
int countOccurrences(String string, int codeUnit) {
var count = 0;