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

Side by Side Diff: utils/pub/hosted_source.dart

Issue 14251006: Remove AsyncError with Expando. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 8 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 | « utils/pub/error_group.dart ('k') | utils/pub/http.dart » ('j') | 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 library hosted_source; 5 library hosted_source;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io' as io; 8 import 'dart:io' as io;
9 import 'dart:json' as json; 9 import 'dart:json' as json;
10 import 'dart:uri'; 10 import 'dart:uri';
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 _getSourceDirectory(_defaultUrl)); 123 _getSourceDirectory(_defaultUrl));
124 if (!dirExists(cacheDir)) return []; 124 if (!dirExists(cacheDir)) return [];
125 125
126 return listDir(path.join(cacheDir)).map((entry) => 126 return listDir(path.join(cacheDir)).map((entry) =>
127 new Package.load(null, entry, systemCache.sources)).toList(); 127 new Package.load(null, entry, systemCache.sources)).toList();
128 } 128 }
129 129
130 /// When an error occurs trying to read something about [package] from [url], 130 /// When an error occurs trying to read something about [package] from [url],
131 /// this tries to translate into a more user friendly error message. Always 131 /// this tries to translate into a more user friendly error message. Always
132 /// throws an error, either the original one or a better one. 132 /// throws an error, either the original one or a better one.
133 void _throwFriendlyError(AsyncError asyncError, package, url) { 133 void _throwFriendlyError(error, package, url) {
134 if (asyncError.error is PubHttpException && 134 if (error is PubHttpException &&
135 asyncError.error.response.statusCode == 404) { 135 error.response.statusCode == 404) {
136 throw 'Could not find package "$package" at $url.'; 136 throw 'Could not find package "$package" at $url.';
137 } 137 }
138 138
139 if (asyncError.error is TimeoutException) { 139 if (error is TimeoutException) {
140 throw 'Timed out trying to find package "$package" at $url.'; 140 throw 'Timed out trying to find package "$package" at $url.';
141 } 141 }
142 142
143 if (asyncError.error is io.SocketIOException) { 143 if (error is io.SocketIOException) {
144 throw 'Got socket error trying to find package "$package" at $url.\n' 144 throw 'Got socket error trying to find package "$package" at $url.\n'
145 '${asyncError.error.osError}'; 145 '${error.osError}';
146 } 146 }
147 147
148 // Otherwise re-throw the original exception. 148 // Otherwise re-throw the original exception.
149 throw asyncError; 149 throw error;
150 } 150 }
151 151
152 } 152 }
153 153
154 /// The URL of the default package repository. 154 /// The URL of the default package repository.
155 final _defaultUrl = "https://pub.dartlang.org"; 155 final _defaultUrl = "https://pub.dartlang.org";
156 156
157 String _getSourceDirectory(String url) { 157 String _getSourceDirectory(String url) {
158 return url.replaceAll(new RegExp(r"^https?://"), ""); 158 return url.replaceAll(new RegExp(r"^https?://"), "");
159 } 159 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 200 }
201 201
202 var name = description["name"]; 202 var name = description["name"];
203 if (name is! String) { 203 if (name is! String) {
204 throw new FormatException("The 'name' key must have a string value."); 204 throw new FormatException("The 'name' key must have a string value.");
205 } 205 }
206 206
207 var url = description.containsKey("url") ? description["url"] : _defaultUrl; 207 var url = description.containsKey("url") ? description["url"] : _defaultUrl;
208 return new Pair<String, String>(name, url); 208 return new Pair<String, String>(name, url);
209 } 209 }
OLDNEW
« no previous file with comments | « utils/pub/error_group.dart ('k') | utils/pub/http.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698