| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /// Generic utility functions. Stuff that should possibly be in core. | 5 /// Generic utility functions. Stuff that should possibly be in core. |
| 6 library pub.utils; | 6 library pub.utils; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import "dart:collection"; | 9 import "dart:collection"; |
| 10 import "dart:convert"; | 10 import "dart:convert"; |
| 11 import 'dart:io'; | 11 import 'dart:io'; |
| 12 import 'dart:isolate'; | 12 import 'dart:isolate'; |
| 13 @MirrorsUsed(targets: 'pub.io') | 13 @MirrorsUsed(targets: 'pub.io') |
| 14 import 'dart:mirrors'; | 14 import 'dart:mirrors'; |
| 15 | 15 |
| 16 import "package:analyzer/analyzer.dart"; | 16 import "package:analyzer/analyzer.dart"; |
| 17 import "package:crypto/crypto.dart"; | 17 import "package:crypto/crypto.dart"; |
| 18 import "package:http/http.dart" as http; |
| 18 import 'package:path/path.dart' as path; | 19 import 'package:path/path.dart' as path; |
| 19 import "package:stack_trace/stack_trace.dart"; | 20 import "package:stack_trace/stack_trace.dart"; |
| 20 | 21 |
| 21 import '../../asset/dart/serialize.dart'; | 22 import '../../asset/dart/serialize.dart'; |
| 22 | 23 |
| 23 export '../../asset/dart/utils.dart'; | 24 export '../../asset/dart/utils.dart'; |
| 24 | 25 |
| 25 /// A pair of values. | 26 /// A pair of values. |
| 26 class Pair<E, F> { | 27 class Pair<E, F> { |
| 27 E first; | 28 E first; |
| (...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 } | 827 } |
| 827 | 828 |
| 828 /// Throw a [ApplicationException] with [message]. | 829 /// Throw a [ApplicationException] with [message]. |
| 829 void fail(String message, [innerError, StackTrace innerTrace]) { | 830 void fail(String message, [innerError, StackTrace innerTrace]) { |
| 830 throw new ApplicationException(message, innerError, innerTrace); | 831 throw new ApplicationException(message, innerError, innerTrace); |
| 831 } | 832 } |
| 832 | 833 |
| 833 /// All the names of user-facing exceptions. | 834 /// All the names of user-facing exceptions. |
| 834 final _userFacingExceptions = new Set<String>.from([ | 835 final _userFacingExceptions = new Set<String>.from([ |
| 835 'ApplicationException', | 836 'ApplicationException', |
| 837 // This refers to http.ClientException. |
| 838 'ClientException', |
| 836 // Errors coming from the Dart analyzer are probably caused by syntax errors | 839 // Errors coming from the Dart analyzer are probably caused by syntax errors |
| 837 // in user code, so they're user-facing. | 840 // in user code, so they're user-facing. |
| 838 'AnalyzerError', 'AnalyzerErrorGroup', | 841 'AnalyzerError', 'AnalyzerErrorGroup', |
| 839 // An error spawning an isolate probably indicates a transformer with an | 842 // An error spawning an isolate probably indicates a transformer with an |
| 840 // invalid import. | 843 // invalid import. |
| 841 'IsolateSpawnException', | 844 'IsolateSpawnException', |
| 842 // TODO(nweiz): clean up the dart:io errors when issue 9955 is fixed. | 845 // TODO(nweiz): clean up the dart:io errors when issue 9955 is fixed. |
| 843 'FileSystemException', 'HttpException', 'HttpException', 'OSError', | 846 'FileSystemException', 'HttpException', 'OSError', |
| 844 'ProcessException', 'SocketException', 'WebSocketException' | 847 'ProcessException', 'SocketException', 'WebSocketException' |
| 845 ]); | 848 ]); |
| 846 | 849 |
| 847 /// Returns whether [error] is a user-facing error object. This includes both | 850 /// Returns whether [error] is a user-facing error object. This includes both |
| 848 /// [ApplicationException] and any dart:io errors. | 851 /// [ApplicationException] and any dart:io errors. |
| 849 bool isUserFacingException(error) { | 852 bool isUserFacingException(error) { |
| 850 if (error is CrossIsolateException) { | 853 if (error is CrossIsolateException) { |
| 851 return _userFacingExceptions.contains(error.type); | 854 return _userFacingExceptions.contains(error.type); |
| 852 } | 855 } |
| 853 | 856 |
| 854 // TODO(nweiz): unify this list with _userFacingExceptions when issue 5897 is | 857 // TODO(nweiz): unify this list with _userFacingExceptions when issue 5897 is |
| 855 // fixed. | 858 // fixed. |
| 856 return error is ApplicationException || | 859 return error is ApplicationException || |
| 857 error is AnalyzerError || | 860 error is AnalyzerError || |
| 858 error is AnalyzerErrorGroup || | 861 error is AnalyzerErrorGroup || |
| 859 error is IsolateSpawnException || | 862 error is IsolateSpawnException || |
| 860 error is FileSystemException || | 863 error is FileSystemException || |
| 861 error is HttpException || | 864 error is HttpException || |
| 862 error is HttpException || | 865 error is http.ClientException || |
| 863 error is OSError || | 866 error is OSError || |
| 864 error is ProcessException || | 867 error is ProcessException || |
| 865 error is SocketException || | 868 error is SocketException || |
| 866 error is WebSocketException; | 869 error is WebSocketException; |
| 867 } | 870 } |
| OLD | NEW |