From 5f20d0a4310d2ac15542cab0269d9a7f3314a38e Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Wed, 6 Jan 2021 13:54:16 -0800 Subject: [PATCH 1/2] Release 1.0.0-beta.6 --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 4901ad9..36cfd4e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: sass_embedded -version: 1.0.0-dev +version: 1.0.0-beta.6 description: An implementation of the Sass embedded protocol using Dart Sass. author: Sass Team homepage: https://github.com/sass/dart-sass-embedded From d37212b3bbf92e9bff8278e8269c794bef5e09ca Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Wed, 6 Jan 2021 15:56:18 -0800 Subject: [PATCH 2/2] Use 0xffffffff as the fallback error ID See sass/embedded-protocol#45 --- lib/src/dispatcher.dart | 6 +++--- lib/src/host_callable.dart | 2 +- lib/src/utils.dart | 11 +++++++---- test/function_test.dart | 31 ++++++++++++++++++------------- test/importer_test.dart | 7 ++++--- test/utils.dart | 5 +++-- 6 files changed, 36 insertions(+), 26 deletions(-) diff --git a/lib/src/dispatcher.dart b/lib/src/dispatcher.dart index ded7787..fcbd814 100644 --- a/lib/src/dispatcher.dart +++ b/lib/src/dispatcher.dart @@ -86,9 +86,9 @@ class Dispatcher { "Unknown message type: ${message.toDebugString()}"); } } on ProtocolError catch (error) { - error.id = _inboundId(message) ?? -1; + error.id = _inboundId(message) ?? errorId; stderr.write("Host caused ${error.type.name.toLowerCase()} error"); - if (error.id != -1) stderr.write(" with request ${error.id}"); + if (error.id != errorId) stderr.write(" with request ${error.id}"); stderr.writeln(": ${error.message}"); sendError(error); // PROTOCOL error from https://bit.ly/2poTt90 @@ -99,7 +99,7 @@ class Dispatcher { stderr.write("Internal compiler error: $errorMessage"); sendError(ProtocolError() ..type = ProtocolError_ErrorType.INTERNAL - ..id = _inboundId(message) ?? -1 + ..id = _inboundId(message) ?? errorId ..message = errorMessage); _channel.sink.close(); } diff --git a/lib/src/host_callable.dart b/lib/src/host_callable.dart index 87cd2dd..e3990aa 100644 --- a/lib/src/host_callable.dart +++ b/lib/src/host_callable.dart @@ -70,7 +70,7 @@ sass.Callable hostCallable(Dispatcher dispatcher, FunctionRegistry functions, // dart-lang/sdk#38790 throw "Unknown FunctionCallResponse.result $response."; } on ProtocolError catch (error) { - error.id = -1; + error.id = errorId; stderr.writeln("Host caused ${error.type.name.toLowerCase()} error: " "${error.message}"); dispatcher.sendError(error); diff --git a/lib/src/utils.dart b/lib/src/utils.dart index 8d34bd2..d89c27d 100644 --- a/lib/src/utils.dart +++ b/lib/src/utils.dart @@ -8,6 +8,10 @@ import 'package:source_span/source_span.dart'; import 'embedded_sass.pb.dart' as proto; import 'embedded_sass.pb.dart' hide SourceSpan; +/// The special ID that indicates an error that's not associated with a specific +/// inbound request ID. +const errorId = 0xffffffff; + /// Returns a [ProtocolError] indicating that a mandatory field with the given /// [fieldName] was missing. ProtocolError mandatoryError(String fieldName) => @@ -16,10 +20,9 @@ ProtocolError mandatoryError(String fieldName) => /// Returns a [ProtocolError] indicating that the parameters for an inbound /// message were invalid. ProtocolError paramsError(String message) => ProtocolError() - // Set the ID to -1 by default, because that's the required value for errors - // that aren't associated with a specific inbound request ID. This will be - // overwritten by the dispatcher if a request ID is available. - ..id = -1 + // Set the ID to [errorId] by default. This will be overwritten by the + // dispatcher if a request ID is available. + ..id = errorId ..type = ProtocolError_ErrorType.PARAMS ..message = message; diff --git a/test/function_test.dart b/test/function_test.dart index a6d3c3b..fd5e3dd 100644 --- a/test/function_test.dart +++ b/test/function_test.dart @@ -5,6 +5,7 @@ import 'package:test/test.dart'; import 'package:sass_embedded/src/embedded_sass.pb.dart'; +import 'package:sass_embedded/src/utils.dart'; import 'embedded_process.dart'; import 'utils.dart'; @@ -391,7 +392,8 @@ void main() { group("without alpha:", () { group("hue", () { test("0", () async { - expect(await _protofy('hsl(0, 50%, 50%)'), _rgb(191, 64, 64, 1.0)); + expect( + await _protofy('hsl(0, 50%, 50%)'), _rgb(191, 64, 64, 1.0)); }); test("360", () async { @@ -400,24 +402,25 @@ void main() { }); test("below 0", () async { - expect( - await _protofy('hsl(-100, 50%, 50%)'), _rgb(106, 64, 191, 1.0)); + expect(await _protofy('hsl(-100, 50%, 50%)'), + _rgb(106, 64, 191, 1.0)); }); test("between 0 and 360", () async { - expect( - await _protofy('hsl(100, 50%, 50%)'), _rgb(106, 191, 64, 1.0)); + expect(await _protofy('hsl(100, 50%, 50%)'), + _rgb(106, 191, 64, 1.0)); }); test("above 360", () async { - expect( - await _protofy('hsl(560, 50%, 50%)'), _rgb(64, 149, 191, 1.0)); + expect(await _protofy('hsl(560, 50%, 50%)'), + _rgb(64, 149, 191, 1.0)); }); }); group("saturation", () { test("0", () async { - expect(await _protofy('hsl(0, 0%, 50%)'), _rgb(128, 128, 128, 1.0)); + expect( + await _protofy('hsl(0, 0%, 50%)'), _rgb(128, 128, 128, 1.0)); }); test("100", () async { @@ -425,7 +428,8 @@ void main() { }); test("in the middle", () async { - expect(await _protofy('hsl(0, 42%, 50%)'), _rgb(181, 74, 74, 1.0)); + expect( + await _protofy('hsl(0, 42%, 50%)'), _rgb(181, 74, 74, 1.0)); }); }); @@ -435,12 +439,13 @@ void main() { }); test("100", () async { - expect( - await _protofy('hsl(0, 50%, 100%)'), _rgb(255, 255, 255, 1.0)); + expect(await _protofy('hsl(0, 50%, 100%)'), + _rgb(255, 255, 255, 1.0)); }); test("in the middle", () async { - expect(await _protofy('hsl(0, 50%, 42%)'), _rgb(161, 54, 54, 1.0)); + expect( + await _protofy('hsl(0, 50%, 42%)'), _rgb(161, 54, 54, 1.0)); }); }); }); @@ -1242,7 +1247,7 @@ Future _expectDeprotofyError(Value value, message) async { ..id = request.id ..success = value)); - await expectParamsError(_process, -1, message); + await expectParamsError(_process, errorId, message); await _process.kill(); } diff --git a/test/importer_test.dart b/test/importer_test.dart index b5b0171..f60c760 100644 --- a/test/importer_test.dart +++ b/test/importer_test.dart @@ -7,6 +7,7 @@ import 'package:test/test.dart'; import 'package:test_descriptor/test_descriptor.dart' as d; import 'package:sass_embedded/src/embedded_sass.pb.dart'; +import 'package:sass_embedded/src/utils.dart'; import 'embedded_process.dart'; import 'utils.dart'; @@ -30,7 +31,7 @@ void main() { await expectParamsError( process, - -1, + errorId, "Response ID ${request.id + 1} doesn't match any outstanding " "requests."); await process.kill(); @@ -47,7 +48,7 @@ void main() { await expectParamsError( process, - -1, + errorId, "Request ID ${request.id} doesn't match response type " "InboundMessage_ImportResponse."); await process.kill(); @@ -505,7 +506,7 @@ Future _canonicalize(EmbeddedProcess process) async { /// [message] on its protobuf stream and causes the compilation to fail. Future _expectImportParamsError(EmbeddedProcess process, message) async { await expectLater(process.outbound, - emits(isProtocolError(-1, ProtocolError_ErrorType.PARAMS, message))); + emits(isProtocolError(errorId, ProtocolError_ErrorType.PARAMS, message))); var failure = getCompileFailure(await process.outbound.next); expect(failure.message, equals('Protocol error: $message')); diff --git a/test/utils.dart b/test/utils.dart index a934af8..d915266 100644 --- a/test/utils.dart +++ b/test/utils.dart @@ -6,6 +6,7 @@ import 'package:path/path.dart' as p; import 'package:test/test.dart'; import 'package:sass_embedded/src/embedded_sass.pb.dart'; +import 'package:sass_embedded/src/utils.dart'; import 'embedded_process.dart'; @@ -39,7 +40,7 @@ InboundMessage compileString(String css, /// [message] on its protobuf stream and prints a notice on stderr. Future expectParseError(EmbeddedProcess process, message) async { await expectLater(process.outbound, - emits(isProtocolError(-1, ProtocolError_ErrorType.PARSE, message))); + emits(isProtocolError(errorId, ProtocolError_ErrorType.PARSE, message))); var stderrPrefix = "Host caused parse error: "; await expectLater( @@ -56,7 +57,7 @@ Future expectParamsError(EmbeddedProcess process, int id, message) async { emits(isProtocolError(id, ProtocolError_ErrorType.PARAMS, message))); var stderrPrefix = "Host caused params error" - "${id == -1 ? '' : " with request $id"}: "; + "${id == errorId ? '' : " with request $id"}: "; await expectLater( process.stderr, message is String