Skip to content

Commit 83ddeb7

Browse files
authored
Log input id not library (#252)
1 parent cc4d6e1 commit 83ddeb7

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ findTokenField(DartObject o) {
3434
`TypeChecker.firstAnnotationOfExact`. Setting this to `false` will enable you
3535
to check for matching annotations with incomplete type information (at your
3636
own risk).
37+
* Builder logs now log the primary inputs `AssetId` instead of the `library`,
38+
which is more useful for tracking down the actual files.
3739

3840
## 0.6.1+1
3941

lib/src/builder.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,15 @@ Stream<GeneratedOutput> _generate(LibraryElement library,
199199
var libraryReader = new LibraryReader(library);
200200
for (var gen in generators) {
201201
try {
202-
log.finer('Running $gen for $library');
202+
log.finer('Running $gen for ${buildStep.inputId}');
203203
var createdUnit = await gen.generate(libraryReader, buildStep);
204204

205205
if (createdUnit != null && createdUnit.isNotEmpty) {
206-
log.finest(() => 'Generated $createdUnit for $library');
206+
log.finest(() => 'Generated $createdUnit for ${buildStep.inputId}');
207207
yield new GeneratedOutput(gen, createdUnit);
208208
}
209209
} catch (e, stack) {
210-
log.severe('Error running $gen for $library.', e, stack);
210+
log.severe('Error running $gen for ${buildStep.inputId}.', e, stack);
211211
yield new GeneratedOutput.fromError(gen, e, stack);
212212
}
213213
}

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ dev_dependencies:
1515
build_test: ^0.6.0
1616
collection: ^1.1.2
1717
cli_util: '>=0.1.0 <0.2.0'
18+
logging: ^0.11.3
1819
meta: ^1.0.5
1920
test: ^0.12.3
2021
_test_annotations:

test/builder_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import 'dart:async';
77

88
import 'package:build_test/build_test.dart';
9+
import 'package:logging/logging.dart';
910
import 'package:source_gen/source_gen.dart';
1011
import 'package:test/test.dart';
1112

@@ -148,6 +149,16 @@ void main() {
148149
'$pkgName|lib/a.g.dart': contains(customOutput),
149150
});
150151
});
152+
153+
test('Error logs contain original input ids', () async {
154+
var logs = <LogRecord>[];
155+
await testBuilder(new LibraryBuilder(new _ThrowingGenerator()),
156+
{'$pkgName|lib/a.dart': 'void hello() {}'},
157+
onLog: logs.add);
158+
await new Future(() {});
159+
expect(
160+
logs.map((l) => l.message), contains(contains('$pkgName|lib/a.dart')));
161+
});
151162
}
152163

153164
Future _generateTest(CommentGenerator gen, String expectedContent) async {
@@ -182,6 +193,10 @@ class _BadOutputGenerator extends Generator {
182193
Future<String> generate(LibraryReader library, _) async => 'not valid code!';
183194
}
184195

196+
class _ThrowingGenerator extends Generator {
197+
Future<String> generate(_, __) async => throw new UnimplementedError();
198+
}
199+
185200
const pkgName = 'pkg';
186201

187202
const _testLibContent = r'''

0 commit comments

Comments
 (0)