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

Commit

Permalink
Don't return a CompileFailure without a span (#60)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nex3 authored Dec 30, 2021
1 parent 5012b5c commit 21f0219
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

* Allow `ImportResponse.result` to be null.

* Fix a bug where the compiler could return a `CompileFailure` without a span.

## 1.0.0-beta.14

* Support `FileImporter`s.
Expand Down
7 changes: 6 additions & 1 deletion bin/dart_sass_embedded.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import 'dart:io';
import 'dart:convert';

import 'package:path/path.dart' as p;
import 'package:sass/sass.dart' as sass;
import 'package:stream_channel/stream_channel.dart';

Expand Down Expand Up @@ -100,7 +101,11 @@ void main(List<String> args) {
..failure = (OutboundMessage_CompileResponse_CompileFailure()
..message = error.path == null
? error.message
: "${error.message}: ${error.path}");
: "${error.message}: ${error.path}"
..span = (SourceSpan()
..start = SourceSpan_SourceLocation()
..end = SourceSpan_SourceLocation()
..url = p.toUri(request.path).toString()));
}
break;

Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: sass_embedded
version: 1.0.0-dev
version: 1.0.0-beta.15
description: An implementation of the Sass embedded protocol using Dart Sass.
homepage: https://github.com/sass/dart-sass-embedded

Expand All @@ -12,6 +12,7 @@ executables:
dependencies:
async: ">=1.13.0 <3.0.0"
meta: ^1.1.0
path: ^1.6.0
protobuf: ^2.0.0
sass: ^1.42.0
sass_api: ^1.0.0-beta.5
Expand All @@ -24,7 +25,6 @@ dev_dependencies:
cli_pkg: ^1.4.0
grinder: ^0.9.0
protoc_plugin: ^20.0.0
path: ^1.6.0
test: ^1.0.0
test_descriptor: ^2.0.0
yaml: ^3.1.0
Expand Down
6 changes: 5 additions & 1 deletion test/protocol_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,11 @@ void main() {
expect(failure.message, startsWith("Cannot open file: "));
expect(failure.message.replaceFirst("Cannot open file: ", "").trim(),
equalsPath(d.path('test.scss')));
expect(failure.span, equals(SourceSpan()));
expect(failure.span.text, equals(''));
expect(failure.span.context, equals(''));
expect(failure.span.start, equals(SourceSpan_SourceLocation()));
expect(failure.span.end, equals(SourceSpan_SourceLocation()));
expect(failure.span.url, equals(p.toUri(d.path('test.scss')).toString()));
expect(failure.stackTrace, isEmpty);
await process.kill();
});
Expand Down

0 comments on commit 21f0219

Please sign in to comment.