@@ -24,6 +24,7 @@ import '../logger/node_to_dart.dart';
2424import '../parse/scss.dart' ;
2525import '../syntax.dart' ;
2626import '../util/nullable.dart' ;
27+ import '../utils.dart' ;
2728import '../value.dart' ;
2829import '../visitor/serialize.dart' ;
2930import 'function.dart' ;
@@ -56,9 +57,12 @@ void render(
5657 callback (null , result);
5758 }, onError: (Object error, StackTrace stackTrace) {
5859 if (error is SassException ) {
59- callback (_wrapException (error), null );
60+ callback (_wrapException (error, stackTrace ), null );
6061 } else {
61- callback (_newRenderError (error.toString (), status: 3 ), null );
62+ callback (
63+ _newRenderError (error.toString (), getTrace (error) ?? stackTrace,
64+ status: 3 ),
65+ null );
6266 }
6367 });
6468 }
@@ -158,15 +162,16 @@ RenderResult renderSync(RenderOptions options) {
158162 }
159163
160164 return _newRenderResult (options, result, start);
161- } on SassException catch (error) {
162- jsThrow (_wrapException (error));
163- } catch (error) {
164- jsThrow (_newRenderError (error.toString (), status: 3 ));
165+ } on SassException catch (error, stackTrace) {
166+ jsThrow (_wrapException (error, stackTrace));
167+ } catch (error, stackTrace) {
168+ jsThrow (_newRenderError (error.toString (), getTrace (error) ?? stackTrace,
169+ status: 3 ));
165170 }
166171}
167172
168173/// Converts an exception to a [JsError] .
169- JsError _wrapException (Object exception) {
174+ JsError _wrapException (Object exception, StackTrace stackTrace ) {
170175 if (exception is SassException ) {
171176 String file;
172177 var url = exception.span.sourceUrl;
@@ -179,12 +184,15 @@ JsError _wrapException(Object exception) {
179184 }
180185
181186 return _newRenderError (exception.toString ().replaceFirst ("Error: " , "" ),
187+ getTrace (exception) ?? stackTrace,
182188 line: exception.span.start.line + 1 ,
183189 column: exception.span.start.column + 1 ,
184190 file: file,
185191 status: 1 );
186192 } else {
187- return JsError (exception.toString ());
193+ var error = JsError (exception.toString ());
194+ attachJsStack (error, getTrace (exception) ?? stackTrace);
195+ return error;
188196 }
189197}
190198
@@ -203,9 +211,11 @@ List<AsyncCallable> _parseFunctions(RenderOptions options, DateTime start,
203211 Tuple2 <String , ArgumentDeclaration > tuple;
204212 try {
205213 tuple = ScssParser (signature as String ).parseSignature ();
206- } on SassFormatException catch (error) {
207- throw SassFormatException (
208- 'Invalid signature "$signature ": ${error .message }' , error.span);
214+ } on SassFormatException catch (error, stackTrace) {
215+ throwWithTrace (
216+ SassFormatException (
217+ 'Invalid signature "$signature ": ${error .message }' , error.span),
218+ stackTrace);
209219 }
210220
211221 var context = RenderContext (options: _contextOptions (options, start));
@@ -417,13 +427,14 @@ bool _enableSourceMaps(RenderOptions options) =>
417427
418428/// Creates a [JsError] with the given fields added to it so it acts like a Node
419429/// Sass error.
420- JsError _newRenderError (String message,
430+ JsError _newRenderError (String message, StackTrace stackTrace,
421431 {int ? line, int ? column, String ? file, int ? status}) {
422432 var error = JsError (message);
423433 setProperty (error, 'formatted' , 'Error: $message ' );
424434 if (line != null ) setProperty (error, 'line' , line);
425435 if (column != null ) setProperty (error, 'column' , column);
426436 if (file != null ) setProperty (error, 'file' , file);
427437 if (status != null ) setProperty (error, 'status' , status);
438+ attachJsStack (error, stackTrace);
428439 return error;
429440}
0 commit comments