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 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 Loading... |
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 fail('Could not find package "$package" at $url.'); |
137 } | 137 } |
138 | 138 |
139 if (error is TimeoutException) { | 139 if (error is TimeoutException) { |
140 throw 'Timed out trying to find package "$package" at $url.'; | 140 fail('Timed out trying to find package "$package" at $url.'); |
141 } | 141 } |
142 | 142 |
143 if (error is io.SocketIOException) { | 143 if (error is io.SocketIOException) { |
144 throw 'Got socket error trying to find package "$package" at $url.\n' | 144 fail('Got socket error trying to find package "$package" at $url.\n' |
145 '${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 error; | 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"; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 } |
OLD | NEW |