Be more explicit about JSON error handling.
R=rnystrom@google.com
Review URL: https://codereview.chromium.org//1658833002 .
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c85bbe3..d101ea0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 1.0.2
+
+* Be more explicit about `JsonDocumentTransformer`'s error-handling behavior.
+
## 1.0.1
* Fix `MultiChannel`'s constructor to take a `StreamChannel`. This is
diff --git a/lib/src/json_document_transformer.dart b/lib/src/json_document_transformer.dart
index 8d8dcce..19b2e08 100644
--- a/lib/src/json_document_transformer.dart
+++ b/lib/src/json_document_transformer.dart
@@ -17,6 +17,10 @@
///
/// This decodes JSON that's emitted by the transformed channel's stream, and
/// encodes objects so that JSON is passed to the transformed channel's sink.
+///
+/// If the transformed channel emits invalid JSON, this emits a
+/// [FormatException]. If an unencodable object is added to the sink, it
+/// synchronously throws a [JsonUnsupportedObjectError].
class JsonDocumentTransformer
implements StreamChannelTransformer<String, Object> {
/// The underlying codec that implements the encoding and decoding logic.
diff --git a/pubspec.yaml b/pubspec.yaml
index 09df4a7..54e9198 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: stream_channel
-version: 1.0.1
+version: 1.0.2
description: An abstraction for two-way communication channels.
author: Dart Team <misc@dartlang.org>
homepage: https://github.com/dart-lang/stream_channel
diff --git a/test/json_document_transformer_test.dart b/test/json_document_transformer_test.dart
index fec3d2a..65a3497 100644
--- a/test/json_document_transformer_test.dart
+++ b/test/json_document_transformer_test.dart
@@ -47,4 +47,16 @@
transformed.sink.add(new Object());
expect(sinkController.stream.first, completion(equals('"encoded"')));
});
+
+ test("emits a stream error when incoming JSON is malformed", () {
+ var transformed = channel.transform(jsonDocument);
+ streamController.add("{invalid");
+ expect(transformed.stream.first, throwsFormatException);
+ });
+
+ test("synchronously throws if an unencodable object is added", () {
+ var transformed = channel.transform(jsonDocument);
+ expect(() => transformed.sink.add(new Object()),
+ throwsA(new isInstanceOf<JsonUnsupportedObjectError>()));
+ });
}