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

Commit 21f0219

Browse files
authored
Don't return a CompileFailure without a span (#60)
We weren't adding a span for a compile failure due to a path not being found. There's no real source in this situation, so we just create an empty span instead.
1 parent 5012b5c commit 21f0219

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
* Allow `ImportResponse.result` to be null.
99

10+
* Fix a bug where the compiler could return a `CompileFailure` without a span.
11+
1012
## 1.0.0-beta.14
1113

1214
* Support `FileImporter`s.

bin/dart_sass_embedded.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import 'dart:io';
66
import 'dart:convert';
77

8+
import 'package:path/path.dart' as p;
89
import 'package:sass/sass.dart' as sass;
910
import 'package:stream_channel/stream_channel.dart';
1011

@@ -100,7 +101,11 @@ void main(List<String> args) {
100101
..failure = (OutboundMessage_CompileResponse_CompileFailure()
101102
..message = error.path == null
102103
? error.message
103-
: "${error.message}: ${error.path}");
104+
: "${error.message}: ${error.path}"
105+
..span = (SourceSpan()
106+
..start = SourceSpan_SourceLocation()
107+
..end = SourceSpan_SourceLocation()
108+
..url = p.toUri(request.path).toString()));
104109
}
105110
break;
106111

pubspec.yaml

Lines changed: 2 additions & 2 deletions
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.15
33
description: An implementation of the Sass embedded protocol using Dart Sass.
44
homepage: https://github.com/sass/dart-sass-embedded
55

@@ -12,6 +12,7 @@ executables:
1212
dependencies:
1313
async: ">=1.13.0 <3.0.0"
1414
meta: ^1.1.0
15+
path: ^1.6.0
1516
protobuf: ^2.0.0
1617
sass: ^1.42.0
1718
sass_api: ^1.0.0-beta.5
@@ -24,7 +25,6 @@ dev_dependencies:
2425
cli_pkg: ^1.4.0
2526
grinder: ^0.9.0
2627
protoc_plugin: ^20.0.0
27-
path: ^1.6.0
2828
test: ^1.0.0
2929
test_descriptor: ^2.0.0
3030
yaml: ^3.1.0

test/protocol_test.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,11 @@ void main() {
300300
expect(failure.message, startsWith("Cannot open file: "));
301301
expect(failure.message.replaceFirst("Cannot open file: ", "").trim(),
302302
equalsPath(d.path('test.scss')));
303-
expect(failure.span, equals(SourceSpan()));
303+
expect(failure.span.text, equals(''));
304+
expect(failure.span.context, equals(''));
305+
expect(failure.span.start, equals(SourceSpan_SourceLocation()));
306+
expect(failure.span.end, equals(SourceSpan_SourceLocation()));
307+
expect(failure.span.url, equals(p.toUri(d.path('test.scss')).toString()));
304308
expect(failure.stackTrace, isEmpty);
305309
await process.kill();
306310
});

0 commit comments

Comments
 (0)