Skip to content
Snippets Groups Projects
Commit 63280d40 authored by nweiz@google.com's avatar nweiz@google.com Committed by Natalie Weizenbaum
Browse files

Gracefully handle transformers rejecting their configuration.

R=rnystrom@google.com
BUG=16008

Review URL: https://codereview.chromium.org//352923002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge@37752 260f80e4-7a28-3924-810f-c04153c831b5
parent fd1c78aa
No related branches found
No related tags found
No related merge requests found
...@@ -9,9 +9,12 @@ import 'dart:convert'; ...@@ -9,9 +9,12 @@ import 'dart:convert';
import 'dart:isolate'; import 'dart:isolate';
import 'package:barback/barback.dart'; import 'package:barback/barback.dart';
import 'package:source_maps/source_maps.dart';
import 'package:stack_trace/stack_trace.dart';
import '../../../asset/dart/serialize.dart'; import '../../../asset/dart/serialize.dart';
import '../barback.dart'; import '../barback.dart';
import '../exceptions.dart';
import '../dart.dart' as dart; import '../dart.dart' as dart;
import '../log.dart' as log; import '../log.dart' as log;
import '../utils.dart'; import '../utils.dart';
...@@ -112,6 +115,18 @@ class TransformerIsolate { ...@@ -112,6 +115,18 @@ class TransformerIsolate {
.toSet(); .toSet();
log.fine("Transformers from $config: $transformers"); log.fine("Transformers from $config: $transformers");
return transformers; return transformers;
}).catchError((error, stackTrace) {
throw new TransformerLoadError(error, config.span);
}); });
} }
} }
/// An error thrown when a transformer fails to load.
class TransformerLoadError extends SpanException implements WrappedException {
final CrossIsolateException innerError;
Chain get innerChain => innerError.stackTrace;
TransformerLoadError(CrossIsolateException error, Span span)
: innerError = error,
super("Error loading transformer: ${error.message}", span);
}
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS d.file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library pub_tests;
import 'package:scheduled_test/scheduled_test.dart';
import '../descriptor.dart' as d;
import '../test_pub.dart';
import '../serve/utils.dart';
const REJECT_CONFIG_TRANSFORMER = """
import 'dart:async';
import 'package:barback/barback.dart';
class RejectConfigTransformer extends Transformer {
RejectConfigTransformer.asPlugin(BarbackSettings settings) {
throw "I hate these settings!";
}
Future<bool> isPrimary(_) => new Future.value(true);
Future apply(Transform transform) {}
}
""";
main() {
initConfig();
withBarbackVersions("any", () {
integration("a transformer can reject is configuration", () {
d.dir(appPath, [
d.pubspec({
"name": "myapp",
"transformers": [{"myapp/src/transformer": {'foo': 'bar'}}]
}),
d.dir("lib", [d.dir("src", [
d.file("transformer.dart", REJECT_CONFIG_TRANSFORMER)
])])
]).create();
createLockFile('myapp', pkg: ['barback']);
var pub = startPubServe();
pub.stderr.expect(endsWith('Error loading transformer: I hate these '
'settings!'));
pub.shouldExit(1);
});
});
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment