Skip to content
This repository was archived by the owner on May 15, 2023. It is now read-only.

Commit 8968233

Browse files
authored
Merge pull request #26 from sass/release
See sass/embedded-protocol#45
2 parents 8a559fb + d37212b commit 8968233

File tree

7 files changed

+37
-27
lines changed

7 files changed

+37
-27
lines changed

lib/src/dispatcher.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ class Dispatcher {
8686
"Unknown message type: ${message.toDebugString()}");
8787
}
8888
} on ProtocolError catch (error) {
89-
error.id = _inboundId(message) ?? -1;
89+
error.id = _inboundId(message) ?? errorId;
9090
stderr.write("Host caused ${error.type.name.toLowerCase()} error");
91-
if (error.id != -1) stderr.write(" with request ${error.id}");
91+
if (error.id != errorId) stderr.write(" with request ${error.id}");
9292
stderr.writeln(": ${error.message}");
9393
sendError(error);
9494
// PROTOCOL error from https://bit.ly/2poTt90
@@ -99,7 +99,7 @@ class Dispatcher {
9999
stderr.write("Internal compiler error: $errorMessage");
100100
sendError(ProtocolError()
101101
..type = ProtocolError_ErrorType.INTERNAL
102-
..id = _inboundId(message) ?? -1
102+
..id = _inboundId(message) ?? errorId
103103
..message = errorMessage);
104104
_channel.sink.close();
105105
}

lib/src/host_callable.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ sass.Callable hostCallable(Dispatcher dispatcher, FunctionRegistry functions,
7070
// dart-lang/sdk#38790
7171
throw "Unknown FunctionCallResponse.result $response.";
7272
} on ProtocolError catch (error) {
73-
error.id = -1;
73+
error.id = errorId;
7474
stderr.writeln("Host caused ${error.type.name.toLowerCase()} error: "
7575
"${error.message}");
7676
dispatcher.sendError(error);

lib/src/utils.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import 'package:source_span/source_span.dart';
88
import 'embedded_sass.pb.dart' as proto;
99
import 'embedded_sass.pb.dart' hide SourceSpan;
1010

11+
/// The special ID that indicates an error that's not associated with a specific
12+
/// inbound request ID.
13+
const errorId = 0xffffffff;
14+
1115
/// Returns a [ProtocolError] indicating that a mandatory field with the given
1216
/// [fieldName] was missing.
1317
ProtocolError mandatoryError(String fieldName) =>
@@ -16,10 +20,9 @@ ProtocolError mandatoryError(String fieldName) =>
1620
/// Returns a [ProtocolError] indicating that the parameters for an inbound
1721
/// message were invalid.
1822
ProtocolError paramsError(String message) => ProtocolError()
19-
// Set the ID to -1 by default, because that's the required value for errors
20-
// that aren't associated with a specific inbound request ID. This will be
21-
// overwritten by the dispatcher if a request ID is available.
22-
..id = -1
23+
// Set the ID to [errorId] by default. This will be overwritten by the
24+
// dispatcher if a request ID is available.
25+
..id = errorId
2326
..type = ProtocolError_ErrorType.PARAMS
2427
..message = message;
2528

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: sass_embedded
2-
version: 1.0.0-dev
2+
version: 1.0.0-beta.6
33
description: An implementation of the Sass embedded protocol using Dart Sass.
44
author: Sass Team
55
homepage: https://github.com/sass/dart-sass-embedded

test/function_test.dart

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import 'package:test/test.dart';
66

77
import 'package:sass_embedded/src/embedded_sass.pb.dart';
8+
import 'package:sass_embedded/src/utils.dart';
89

910
import 'embedded_process.dart';
1011
import 'utils.dart';
@@ -391,7 +392,8 @@ void main() {
391392
group("without alpha:", () {
392393
group("hue", () {
393394
test("0", () async {
394-
expect(await _protofy('hsl(0, 50%, 50%)'), _rgb(191, 64, 64, 1.0));
395+
expect(
396+
await _protofy('hsl(0, 50%, 50%)'), _rgb(191, 64, 64, 1.0));
395397
});
396398

397399
test("360", () async {
@@ -400,32 +402,34 @@ void main() {
400402
});
401403

402404
test("below 0", () async {
403-
expect(
404-
await _protofy('hsl(-100, 50%, 50%)'), _rgb(106, 64, 191, 1.0));
405+
expect(await _protofy('hsl(-100, 50%, 50%)'),
406+
_rgb(106, 64, 191, 1.0));
405407
});
406408

407409
test("between 0 and 360", () async {
408-
expect(
409-
await _protofy('hsl(100, 50%, 50%)'), _rgb(106, 191, 64, 1.0));
410+
expect(await _protofy('hsl(100, 50%, 50%)'),
411+
_rgb(106, 191, 64, 1.0));
410412
});
411413

412414
test("above 360", () async {
413-
expect(
414-
await _protofy('hsl(560, 50%, 50%)'), _rgb(64, 149, 191, 1.0));
415+
expect(await _protofy('hsl(560, 50%, 50%)'),
416+
_rgb(64, 149, 191, 1.0));
415417
});
416418
});
417419

418420
group("saturation", () {
419421
test("0", () async {
420-
expect(await _protofy('hsl(0, 0%, 50%)'), _rgb(128, 128, 128, 1.0));
422+
expect(
423+
await _protofy('hsl(0, 0%, 50%)'), _rgb(128, 128, 128, 1.0));
421424
});
422425

423426
test("100", () async {
424427
expect(await _protofy('hsl(0, 100%, 50%)'), _rgb(255, 0, 0, 1.0));
425428
});
426429

427430
test("in the middle", () async {
428-
expect(await _protofy('hsl(0, 42%, 50%)'), _rgb(181, 74, 74, 1.0));
431+
expect(
432+
await _protofy('hsl(0, 42%, 50%)'), _rgb(181, 74, 74, 1.0));
429433
});
430434
});
431435

@@ -435,12 +439,13 @@ void main() {
435439
});
436440

437441
test("100", () async {
438-
expect(
439-
await _protofy('hsl(0, 50%, 100%)'), _rgb(255, 255, 255, 1.0));
442+
expect(await _protofy('hsl(0, 50%, 100%)'),
443+
_rgb(255, 255, 255, 1.0));
440444
});
441445

442446
test("in the middle", () async {
443-
expect(await _protofy('hsl(0, 50%, 42%)'), _rgb(161, 54, 54, 1.0));
447+
expect(
448+
await _protofy('hsl(0, 50%, 42%)'), _rgb(161, 54, 54, 1.0));
444449
});
445450
});
446451
});
@@ -1242,7 +1247,7 @@ Future<void> _expectDeprotofyError(Value value, message) async {
12421247
..id = request.id
12431248
..success = value));
12441249

1245-
await expectParamsError(_process, -1, message);
1250+
await expectParamsError(_process, errorId, message);
12461251
await _process.kill();
12471252
}
12481253

test/importer_test.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:test/test.dart';
77
import 'package:test_descriptor/test_descriptor.dart' as d;
88

99
import 'package:sass_embedded/src/embedded_sass.pb.dart';
10+
import 'package:sass_embedded/src/utils.dart';
1011

1112
import 'embedded_process.dart';
1213
import 'utils.dart';
@@ -30,7 +31,7 @@ void main() {
3031

3132
await expectParamsError(
3233
process,
33-
-1,
34+
errorId,
3435
"Response ID ${request.id + 1} doesn't match any outstanding "
3536
"requests.");
3637
await process.kill();
@@ -47,7 +48,7 @@ void main() {
4748

4849
await expectParamsError(
4950
process,
50-
-1,
51+
errorId,
5152
"Request ID ${request.id} doesn't match response type "
5253
"InboundMessage_ImportResponse.");
5354
await process.kill();
@@ -505,7 +506,7 @@ Future<void> _canonicalize(EmbeddedProcess process) async {
505506
/// [message] on its protobuf stream and causes the compilation to fail.
506507
Future<void> _expectImportParamsError(EmbeddedProcess process, message) async {
507508
await expectLater(process.outbound,
508-
emits(isProtocolError(-1, ProtocolError_ErrorType.PARAMS, message)));
509+
emits(isProtocolError(errorId, ProtocolError_ErrorType.PARAMS, message)));
509510

510511
var failure = getCompileFailure(await process.outbound.next);
511512
expect(failure.message, equals('Protocol error: $message'));

test/utils.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:path/path.dart' as p;
66
import 'package:test/test.dart';
77

88
import 'package:sass_embedded/src/embedded_sass.pb.dart';
9+
import 'package:sass_embedded/src/utils.dart';
910

1011
import 'embedded_process.dart';
1112

@@ -39,7 +40,7 @@ InboundMessage compileString(String css,
3940
/// [message] on its protobuf stream and prints a notice on stderr.
4041
Future<void> expectParseError(EmbeddedProcess process, message) async {
4142
await expectLater(process.outbound,
42-
emits(isProtocolError(-1, ProtocolError_ErrorType.PARSE, message)));
43+
emits(isProtocolError(errorId, ProtocolError_ErrorType.PARSE, message)));
4344

4445
var stderrPrefix = "Host caused parse error: ";
4546
await expectLater(
@@ -56,7 +57,7 @@ Future<void> expectParamsError(EmbeddedProcess process, int id, message) async {
5657
emits(isProtocolError(id, ProtocolError_ErrorType.PARAMS, message)));
5758

5859
var stderrPrefix = "Host caused params error"
59-
"${id == -1 ? '' : " with request $id"}: ";
60+
"${id == errorId ? '' : " with request $id"}: ";
6061
await expectLater(
6162
process.stderr,
6263
message is String

0 commit comments

Comments
 (0)