Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1444)

Side by Side Diff: sdk/lib/_internal/pub/lib/src/utils.dart

Issue 315063002: Display timeout errors more gracefully. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/source/hosted.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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";
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 /// path. 613 /// path.
614 String nicePath(String inputPath) { 614 String nicePath(String inputPath) {
615 var relative = path.relative(inputPath); 615 var relative = path.relative(inputPath);
616 var split = path.split(relative); 616 var split = path.split(relative);
617 if (split.length > 1 && split[0] == '..' && split[1] == '..') { 617 if (split.length > 1 && split[0] == '..' && split[1] == '..') {
618 return path.absolute(inputPath); 618 return path.absolute(inputPath);
619 } 619 }
620 return relative; 620 return relative;
621 } 621 }
622 622
623 /// Returns a human-friendly representation of [duration].
624 String niceDuration(Duration duration) {
625 var result = duration.inMinutes > 0 ? "${duration.inMinutes}:" : "";
626
627 var s = duration.inSeconds % 59;
628 var ms = (duration.inMilliseconds % 1000) ~/ 100;
629 return result + "$s.${ms}s";
630 }
631
623 /// Decodes a URL-encoded string. Unlike [Uri.decodeComponent], this includes 632 /// Decodes a URL-encoded string. Unlike [Uri.decodeComponent], this includes
624 /// replacing `+` with ` `. 633 /// replacing `+` with ` `.
625 String urlDecode(String encoded) => 634 String urlDecode(String encoded) =>
626 Uri.decodeComponent(encoded.replaceAll("+", " ")); 635 Uri.decodeComponent(encoded.replaceAll("+", " "));
627 636
628 /// Takes a simple data structure (composed of [Map]s, [Iterable]s, scalar 637 /// Takes a simple data structure (composed of [Map]s, [Iterable]s, scalar
629 /// objects, and [Future]s) and recursively resolves all the [Future]s contained 638 /// objects, and [Future]s) and recursively resolves all the [Future]s contained
630 /// within. Completes with the fully resolved structure. 639 /// within. Completes with the fully resolved structure.
631 Future awaitObject(object) { 640 Future awaitObject(object) {
632 // Unroll nested futures. 641 // Unroll nested futures.
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 // This refers to http.ClientException. 846 // This refers to http.ClientException.
838 'ClientException', 847 'ClientException',
839 // Errors coming from the Dart analyzer are probably caused by syntax errors 848 // Errors coming from the Dart analyzer are probably caused by syntax errors
840 // in user code, so they're user-facing. 849 // in user code, so they're user-facing.
841 'AnalyzerError', 'AnalyzerErrorGroup', 850 'AnalyzerError', 'AnalyzerErrorGroup',
842 // An error spawning an isolate probably indicates a transformer with an 851 // An error spawning an isolate probably indicates a transformer with an
843 // invalid import. 852 // invalid import.
844 'IsolateSpawnException', 853 'IsolateSpawnException',
845 // TODO(nweiz): clean up the dart:io errors when issue 9955 is fixed. 854 // TODO(nweiz): clean up the dart:io errors when issue 9955 is fixed.
846 'FileSystemException', 'HttpException', 'OSError', 855 'FileSystemException', 'HttpException', 'OSError',
847 'ProcessException', 'SocketException', 'WebSocketException' 856 'ProcessException', 'SocketException', 'TimeoutException',
857 'WebSocketException'
848 ]); 858 ]);
849 859
850 /// Returns whether [error] is a user-facing error object. This includes both 860 /// Returns whether [error] is a user-facing error object. This includes both
851 /// [ApplicationException] and any dart:io errors. 861 /// [ApplicationException] and any dart:io errors.
852 bool isUserFacingException(error) { 862 bool isUserFacingException(error) {
853 if (error is CrossIsolateException) { 863 if (error is CrossIsolateException) {
854 return _userFacingExceptions.contains(error.type); 864 return _userFacingExceptions.contains(error.type);
855 } 865 }
856 866
857 // TODO(nweiz): unify this list with _userFacingExceptions when issue 5897 is 867 // TODO(nweiz): unify this list with _userFacingExceptions when issue 5897 is
858 // fixed. 868 // fixed.
859 return error is ApplicationException || 869 return error is ApplicationException ||
860 error is AnalyzerError || 870 error is AnalyzerError ||
861 error is AnalyzerErrorGroup || 871 error is AnalyzerErrorGroup ||
862 error is IsolateSpawnException || 872 error is IsolateSpawnException ||
863 error is FileSystemException || 873 error is FileSystemException ||
864 error is HttpException || 874 error is HttpException ||
865 error is http.ClientException || 875 error is http.ClientException ||
866 error is OSError || 876 error is OSError ||
867 error is ProcessException || 877 error is ProcessException ||
878 error is TimeoutException ||
868 error is SocketException || 879 error is SocketException ||
869 error is WebSocketException; 880 error is WebSocketException;
870 } 881 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/source/hosted.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698