Skip to content

Commit

Permalink
Log input id not library (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakemac53 authored Jul 26, 2017
1 parent cc4d6e1 commit 83ddeb7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ findTokenField(DartObject o) {
`TypeChecker.firstAnnotationOfExact`. Setting this to `false` will enable you
to check for matching annotations with incomplete type information (at your
own risk).
* Builder logs now log the primary inputs `AssetId` instead of the `library`,
which is more useful for tracking down the actual files.

## 0.6.1+1

Expand Down
6 changes: 3 additions & 3 deletions lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,15 @@ Stream<GeneratedOutput> _generate(LibraryElement library,
var libraryReader = new LibraryReader(library);
for (var gen in generators) {
try {
log.finer('Running $gen for $library');
log.finer('Running $gen for ${buildStep.inputId}');
var createdUnit = await gen.generate(libraryReader, buildStep);

if (createdUnit != null && createdUnit.isNotEmpty) {
log.finest(() => 'Generated $createdUnit for $library');
log.finest(() => 'Generated $createdUnit for ${buildStep.inputId}');
yield new GeneratedOutput(gen, createdUnit);
}
} catch (e, stack) {
log.severe('Error running $gen for $library.', e, stack);
log.severe('Error running $gen for ${buildStep.inputId}.', e, stack);
yield new GeneratedOutput.fromError(gen, e, stack);
}
}
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dev_dependencies:
build_test: ^0.6.0
collection: ^1.1.2
cli_util: '>=0.1.0 <0.2.0'
logging: ^0.11.3
meta: ^1.0.5
test: ^0.12.3
_test_annotations:
Expand Down
15 changes: 15 additions & 0 deletions test/builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import 'dart:async';

import 'package:build_test/build_test.dart';
import 'package:logging/logging.dart';
import 'package:source_gen/source_gen.dart';
import 'package:test/test.dart';

Expand Down Expand Up @@ -148,6 +149,16 @@ void main() {
'$pkgName|lib/a.g.dart': contains(customOutput),
});
});

test('Error logs contain original input ids', () async {
var logs = <LogRecord>[];
await testBuilder(new LibraryBuilder(new _ThrowingGenerator()),
{'$pkgName|lib/a.dart': 'void hello() {}'},
onLog: logs.add);
await new Future(() {});
expect(
logs.map((l) => l.message), contains(contains('$pkgName|lib/a.dart')));
});
}

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

class _ThrowingGenerator extends Generator {
Future<String> generate(_, __) async => throw new UnimplementedError();
}

const pkgName = 'pkg';

const _testLibContent = r'''
Expand Down

0 comments on commit 83ddeb7

Please sign in to comment.