Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 0.5.4+4
## 0.5.5

* Support package:build 0.8.x
* Less verbose errors when analyzer fails to resolve the input.

## 0.5.4+3

Expand Down
7 changes: 6 additions & 1 deletion lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import 'dart:async';

import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/exception/exception.dart';
import 'package:build/build.dart';
import 'package:dart_style/src/dart_formatter.dart';

Expand Down Expand Up @@ -98,7 +99,11 @@ class GeneratorBuilder extends Builder {

Stream<GeneratedOutput> _generate(LibraryElement unit,
List<Generator> generators, BuildStep buildStep) async* {
for (var element in getElementsFromLibraryElement(unit)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before, this would just blow up.

Now it'll succeed, but log errors, right? Or are we treating severe logs as fatal?

Just trying to understand...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

severe logs are fatal in bazel and build_barback.
They are tolerated in build_runner but we want to change that: dart-lang/build#215

var elements = safeIterate(getElementsFromLibraryElement(unit), (e, [_]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like in general we could just handle this inside of getElementsFromLibraryElement or _getElements (whichever is throwing).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could. It would introduce a package:build import into utils.darts so we could do the logging, and we'd probably end up needing to pass through the buildStep or inputId which IMO degrades from the nice separation we have now.

My preference would be this layout, WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am OK with it as is, that would be somewhat annoying for sure.

log.fine('Resolve error details:\n$e');
log.severe('Failed to resolve ${buildStep.inputId}.');
});
for (var element in elements) {
yield* _processUnitMember(element, generators, buildStep);
}
}
Expand Down
14 changes: 14 additions & 0 deletions lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ Iterable<Element> getElementsFromLibraryElement(LibraryElement unit) sync* {
}
}

/// Returns an Iterable that will not throw any exceptions while iterating.
///
/// If an exception occurs while iterating [iterable] the return value will
/// finish and [onError] will be called.
Iterable<T> safeIterate<T>(Iterable<T> iterable, void onError(e, st)) sync* {
try {
for (var e in iterable) {
yield e;
}
} catch (e, st) {
onError(e, st);
}
}

Iterable<Element> _getElements(CompilationUnitMember member) {
if (member is TopLevelVariableDeclaration) {
return member.variables.variables
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: source_gen
version: 0.5.4+4
version: 0.5.5
author: Dart Team <misc@dartlang.org>
description: Automatic sourcecode generation for Dart
homepage: https://github.com/dart-lang/source_gen
environment:
sdk: '>=1.12.0 <2.0.0'
sdk: '>=1.21.1 <2.0.0'
dependencies:
analyzer: ^0.29.2
build: '>=0.7.1 <0.9.0'
Expand Down