Line data Source code
1 : // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 2 : // for details. All rights reserved. Use of this source code is governed by a 3 : // BSD-style license that can be found in the LICENSE file. 4 : 5 : import 'package:source_span/source_span.dart'; 6 : 7 : import '../util/errors.dart'; 8 : 9 : class LoadException implements Exception { 10 : final String path; 11 : 12 : final Object innerError; 13 : 14 0 : LoadException(this.path, this.innerError); 15 : 16 0 : @override 17 : String toString({bool color = false}) { 18 0 : var buffer = StringBuffer(); 19 0 : if (color) buffer.write('\u001b[31m'); // red 20 0 : buffer.write('Failed to load "$path":'); 21 0 : if (color) buffer.write('\u001b[0m'); // no color 22 : 23 0 : var innerString = getErrorMessage(innerError); 24 0 : if (innerError is SourceSpanException) { 25 0 : innerString = (innerError as SourceSpanException) 26 0 : .toString(color: color) 27 0 : .replaceFirst(' of $path', ''); 28 : } 29 : 30 0 : buffer.write(innerString.contains('\n') ? '\n' : ' '); 31 0 : buffer.write(innerString); 32 0 : return buffer.toString(); 33 : } 34 : }