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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 /// given name from the default host, while a map with keys "name" and "url" | 113 /// given name from the default host, while a map with keys "name" and "url" |
114 /// refers to a package with the given name from the host at the given URL. | 114 /// refers to a package with the given name from the host at the given URL. |
115 void validateDescription(description, {bool fromLockFile: false}) { | 115 void validateDescription(description, {bool fromLockFile: false}) { |
116 _parseDescription(description); | 116 _parseDescription(description); |
117 } | 117 } |
118 | 118 |
119 /// When an error occurs trying to read something about [package] from [url], | 119 /// When an error occurs trying to read something about [package] from [url], |
120 /// this tries to translate into a more user friendly error message. Always | 120 /// this tries to translate into a more user friendly error message. Always |
121 /// throws an error, either the original one or a better one. | 121 /// throws an error, either the original one or a better one. |
122 void _throwFriendlyError(AsyncError asyncError, package, url) { | 122 void _throwFriendlyError(AsyncError asyncError, package, url) { |
123 var ex = getRealError(asyncError); | 123 if (asyncError.error is PubHttpException && |
124 | 124 asyncError.error.response.statusCode == 404) { |
125 if (ex is PubHttpException && ex.response.statusCode == 404) { | |
126 throw 'Could not find package "$package" at $url.'; | 125 throw 'Could not find package "$package" at $url.'; |
127 } | 126 } |
128 | 127 |
129 if (ex is TimeoutException) { | 128 if (asyncError.error is TimeoutException) { |
130 throw 'Timed out trying to find package "$package" at $url.'; | 129 throw 'Timed out trying to find package "$package" at $url.'; |
131 } | 130 } |
132 | 131 |
133 if (ex is io.SocketIOException) { | 132 if (asyncError.error is io.SocketIOException) { |
134 throw 'Got socket error trying to find package "$package" at $url.\n' | 133 throw 'Got socket error trying to find package "$package" at $url.\n' |
135 '${ex.osError}'; | 134 '${asyncError.error.osError}'; |
136 } | 135 } |
137 | 136 |
138 // Otherwise re-throw the original exception. | 137 // Otherwise re-throw the original exception. |
139 throw asyncError; | 138 throw asyncError; |
140 } | 139 } |
141 | 140 |
142 /// Parses the description for a package. | 141 /// Parses the description for a package. |
143 /// | 142 /// |
144 /// If the package parses correctly, this returns a (name, url) pair. If not, | 143 /// If the package parses correctly, this returns a (name, url) pair. If not, |
145 /// this throws a descriptive FormatException. | 144 /// this throws a descriptive FormatException. |
(...skipping 14 matching lines...) Expand all Loading... |
160 | 159 |
161 var name = description["name"]; | 160 var name = description["name"]; |
162 if (name is! String) { | 161 if (name is! String) { |
163 throw new FormatException("The 'name' key must have a string value."); | 162 throw new FormatException("The 'name' key must have a string value."); |
164 } | 163 } |
165 | 164 |
166 var url = description.containsKey("url") ? description["url"] : defaultUrl; | 165 var url = description.containsKey("url") ? description["url"] : defaultUrl; |
167 return new Pair<String, String>(name, url); | 166 return new Pair<String, String>(name, url); |
168 } | 167 } |
169 } | 168 } |
OLD | NEW |