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

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

Issue 14253005: Migrate pub away from throwing strings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(error, package, url) { 133 void _throwFriendlyError(error, package, url) {
134 if (error is PubHttpException && 134 if (error is PubHttpException &&
135 error.response.statusCode == 404) { 135 error.response.statusCode == 404) {
136 throw 'Could not find package "$package" at $url.'; 136 throw new UserFacingException('Could not find package "$package" at '
137 '$url.');
137 } 138 }
138 139
139 if (error is TimeoutException) { 140 if (error is TimeoutException) {
140 throw 'Timed out trying to find package "$package" at $url.'; 141 throw new UserFacingException('Timed out trying to find package '
142 '"$package" at $url.');
141 } 143 }
142 144
143 if (error is io.SocketIOException) { 145 if (error is io.SocketIOException) {
144 throw 'Got socket error trying to find package "$package" at $url.\n' 146 throw new UserFacingException('Got socket error trying to find package '
145 '${error.osError}'; 147 '"$package" at $url.\n'
Bob Nystrom 2013/04/18 18:18:31 Nit, but I would probably move the whole string to
nweiz 2013/04/18 18:37:24 This was reformatted anyway due to [fail].
148 '${error.osError}');
146 } 149 }
147 150
148 // Otherwise re-throw the original exception. 151 // Otherwise re-throw the original exception.
149 throw error; 152 throw error;
150 } 153 }
151 154
152 } 155 }
153 156
154 /// The URL of the default package repository. 157 /// The URL of the default package repository.
155 final _defaultUrl = "https://pub.dartlang.org"; 158 final _defaultUrl = "https://pub.dartlang.org";
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 203 }
201 204
202 var name = description["name"]; 205 var name = description["name"];
203 if (name is! String) { 206 if (name is! String) {
204 throw new FormatException("The 'name' key must have a string value."); 207 throw new FormatException("The 'name' key must have a string value.");
205 } 208 }
206 209
207 var url = description.containsKey("url") ? description["url"] : _defaultUrl; 210 var url = description.containsKey("url") ? description["url"] : _defaultUrl;
208 return new Pair<String, String>(name, url); 211 return new Pair<String, String>(name, url);
209 } 212 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698