2016-09-03 16:42:29 +02:00
|
|
|
// Copyright 2016 Google Inc. Use of this source code is governed by an
|
|
|
|
// MIT-style license that can be found in the LICENSE file or at
|
|
|
|
// https://opensource.org/licenses/MIT.
|
|
|
|
|
|
|
|
import 'package:source_span/source_span.dart';
|
2016-09-03 18:18:28 +02:00
|
|
|
import 'package:stack_trace/stack_trace.dart';
|
2016-09-03 16:42:29 +02:00
|
|
|
|
2016-10-10 05:57:10 +02:00
|
|
|
/// An exception thrown by Sass.
|
2016-09-03 16:42:29 +02:00
|
|
|
class SassException extends SourceSpanException {
|
|
|
|
FileSpan get span => super.span as FileSpan;
|
|
|
|
|
|
|
|
SassException(String message, FileSpan span) : super(message, span);
|
|
|
|
}
|
|
|
|
|
2016-10-10 05:57:10 +02:00
|
|
|
/// An exception thrown by Sass while evaluating a stylesheet.
|
2016-09-03 18:18:28 +02:00
|
|
|
class SassRuntimeException extends SassException {
|
2016-10-10 05:57:10 +02:00
|
|
|
/// The Sass stack trace at the point this exception was thrown.
|
2016-09-03 18:18:28 +02:00
|
|
|
final Trace trace;
|
|
|
|
|
|
|
|
SassRuntimeException(String message, FileSpan span, this.trace)
|
|
|
|
: super(message, span);
|
|
|
|
|
|
|
|
String toString({color}) {
|
|
|
|
var buffer = new StringBuffer(super.toString(color: color));
|
|
|
|
for (var frame in trace.toString().split("\n")) {
|
|
|
|
if (frame.isEmpty) continue;
|
|
|
|
buffer.writeln();
|
|
|
|
buffer.write(" $frame");
|
|
|
|
}
|
|
|
|
return buffer.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-10 05:57:10 +02:00
|
|
|
/// An exception thrown when Sass parsing has failed.
|
2016-09-03 16:42:29 +02:00
|
|
|
class SassFormatException extends SourceSpanFormatException
|
|
|
|
implements SassException {
|
|
|
|
FileSpan get span => super.span as FileSpan;
|
|
|
|
|
|
|
|
String get source => span.file.getText(0);
|
|
|
|
|
|
|
|
SassFormatException(String message, FileSpan span) : super(message, span);
|
|
|
|
}
|
2016-09-03 17:20:00 +02:00
|
|
|
|
2016-10-17 03:46:38 +02:00
|
|
|
/// An exception thrown by SassScript.
|
2016-10-10 05:57:10 +02:00
|
|
|
///
|
2016-10-17 03:46:38 +02:00
|
|
|
/// This doesn't extends [SassException] because it doesn't (yet) have a
|
|
|
|
/// [FileSpan] associated with it. It's caught by Sass's internals and converted
|
|
|
|
/// to a [SassRuntimeException] with a source span and a stack trace.
|
|
|
|
class SassScriptException {
|
2016-10-10 05:57:10 +02:00
|
|
|
/// The error message.
|
2016-09-03 17:20:00 +02:00
|
|
|
final String message;
|
|
|
|
|
2016-10-17 03:46:38 +02:00
|
|
|
SassScriptException(this.message);
|
2016-09-03 17:20:00 +02:00
|
|
|
|
|
|
|
String toString() => "$message\n\nBUG: This should include a source span!";
|
|
|
|
}
|