mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 06:20:13 +00:00
Stop working around issue 7781 in Pub.
Review URL: https://codereview.chromium.org//11881032 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@17038 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
parent
a152bc270c
commit
30d2e78687
9 changed files with 29 additions and 63 deletions
|
@ -72,16 +72,15 @@ class LishCommand extends PubCommand {
|
|||
}).then((location) => client.get(location))
|
||||
.then(handleJsonSuccess);
|
||||
}).catchError((asyncError) {
|
||||
var e = getRealError(asyncError);
|
||||
if (e is! PubHttpException) throw asyncError;
|
||||
var url = e.response.request.url;
|
||||
if (asyncError.error is! PubHttpException) throw asyncError;
|
||||
var url = asyncError.error.response.request.url;
|
||||
if (url.toString() == cloudStorageUrl.toString()) {
|
||||
// TODO(nweiz): the response may have XML-formatted information about
|
||||
// the error. Try to parse that out once we have an easily-accessible
|
||||
// XML parser.
|
||||
throw 'Failed to upload the package.';
|
||||
} else if (url.origin == server.origin) {
|
||||
handleJsonError(e.response);
|
||||
handleJsonError(asyncError.error.response);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -77,9 +77,8 @@ class UploaderCommand extends PubCommand {
|
|||
}
|
||||
});
|
||||
}).then(handleJsonSuccess).catchError((asyncError) {
|
||||
var e = getRealError(asyncError);
|
||||
if (e is! PubHttpException) throw asyncError;
|
||||
handleJsonError(e.response);
|
||||
if (asyncError.error is! PubHttpException) throw asyncError;
|
||||
handleJsonError(asyncError.error.response);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -120,19 +120,18 @@ class HostedSource extends Source {
|
|||
/// this tries to translate into a more user friendly error message. Always
|
||||
/// throws an error, either the original one or a better one.
|
||||
void _throwFriendlyError(AsyncError asyncError, package, url) {
|
||||
var ex = getRealError(asyncError);
|
||||
|
||||
if (ex is PubHttpException && ex.response.statusCode == 404) {
|
||||
if (asyncError.error is PubHttpException &&
|
||||
asyncError.error.response.statusCode == 404) {
|
||||
throw 'Could not find package "$package" at $url.';
|
||||
}
|
||||
|
||||
if (ex is TimeoutException) {
|
||||
if (asyncError.error is TimeoutException) {
|
||||
throw 'Timed out trying to find package "$package" at $url.';
|
||||
}
|
||||
|
||||
if (ex is io.SocketIOException) {
|
||||
if (asyncError.error is io.SocketIOException) {
|
||||
throw 'Got socket error trying to find package "$package" at $url.\n'
|
||||
'${ex.osError}';
|
||||
'${asyncError.error.osError}';
|
||||
}
|
||||
|
||||
// Otherwise re-throw the original exception.
|
||||
|
|
|
@ -58,13 +58,12 @@ class PubHttpClient extends http.BaseClient {
|
|||
throw new PubHttpException(response);
|
||||
});
|
||||
}).catchError((asyncError) {
|
||||
var e = getRealError(asyncError);
|
||||
if (e is SocketIOException &&
|
||||
e.osError != null &&
|
||||
(e.osError.errorCode == 8 ||
|
||||
e.osError.errorCode == -2 ||
|
||||
e.osError.errorCode == -5 ||
|
||||
e.osError.errorCode == 11004)) {
|
||||
if (asyncError.error is SocketIOException &&
|
||||
asyncError.error.osError != null &&
|
||||
(asyncError.error.osError.errorCode == 8 ||
|
||||
asyncError.error.osError.errorCode == -2 ||
|
||||
asyncError.error.osError.errorCode == -5 ||
|
||||
asyncError.error.osError.errorCode == 11004)) {
|
||||
throw 'Could not resolve URL "${request.url.origin}".';
|
||||
}
|
||||
throw asyncError;
|
||||
|
|
|
@ -189,10 +189,10 @@ Future<Directory> ensureDir(path) {
|
|||
|
||||
return ensureDir(dirname(path)).then((_) {
|
||||
return createDir(path).catchError((asyncError) {
|
||||
var error = getRealError(asyncError);
|
||||
if (error is! DirectoryIOException) throw asyncError;
|
||||
if (asyncError.error is! DirectoryIOException) throw asyncError;
|
||||
// Error 17 means the directory already exists (or 183 on Windows).
|
||||
if (error.osError.errorCode == 17 || error.osError.errorCode == 183) {
|
||||
if (asyncError.error.osError.errorCode == 17 ||
|
||||
asyncError.error.osError.errorCode == 183) {
|
||||
log.fine("Got 'already exists' error when creating directory.");
|
||||
return _getDirectory(path);
|
||||
}
|
||||
|
|
|
@ -75,14 +75,15 @@ Future withClient(SystemCache cache, Future fn(Client client)) {
|
|||
return _saveCredentials(cache, client.credentials);
|
||||
});
|
||||
}).catchError((asyncError) {
|
||||
var e = getRealError(asyncError);
|
||||
if (e is ExpirationException) {
|
||||
if (asyncError.error is ExpirationException) {
|
||||
log.error("Pub's authorization to upload packages has expired and "
|
||||
"can't be automatically refreshed.");
|
||||
return withClient(cache, fn);
|
||||
} else if (e is AuthorizationException) {
|
||||
} else if (asyncError.error is AuthorizationException) {
|
||||
var message = "OAuth2 authorization failed";
|
||||
if (e.description != null) message = "$message (${e.description})";
|
||||
if (asyncError.error.description != null) {
|
||||
message = "$message (${asyncError.error.description})";
|
||||
}
|
||||
log.error("$message.");
|
||||
return clearCredentials(cache).then((_) => withClient(cache, fn));
|
||||
} else {
|
||||
|
|
|
@ -262,7 +262,7 @@ abstract class PubCommand {
|
|||
future
|
||||
.then((_) => cache_.deleteTempDir())
|
||||
.catchError((asyncError) {
|
||||
var e = getRealError(asyncError);
|
||||
var e = asyncError.error;
|
||||
if (e is PubspecNotFoundException && e.name == null) {
|
||||
e = 'Could not find a file named "pubspec.yaml" in the directory '
|
||||
'${path.current}.';
|
||||
|
@ -271,7 +271,7 @@ abstract class PubCommand {
|
|||
'${basename(path.current)}").';
|
||||
}
|
||||
|
||||
handleError(e, getRealStackTrace(asyncError));
|
||||
handleError(e, asyncError.stackTrace);
|
||||
})
|
||||
// Explicitly exit on success to ensure that any dangling dart:io handles
|
||||
// don't cause the process to never terminate.
|
||||
|
|
|
@ -177,27 +177,3 @@ void mapAddAll(Map destination, Map source) =>
|
|||
/// replacing `+` with ` `.
|
||||
String urlDecode(String encoded) =>
|
||||
decodeUriComponent(encoded.replaceAll("+", " "));
|
||||
|
||||
// TODO(rnystrom): Remove this when #7781 is fixed.
|
||||
/// When an error is rethrown in an async callback, you can end up with nested
|
||||
/// AsyncErrors. This unwraps them to find the real originating error.
|
||||
getRealError(error) {
|
||||
while (error is AsyncError) {
|
||||
error = error.error;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
// TODO(nweiz): Remove this when #7781 is fixed.
|
||||
/// When an error is rethrown in an async callback, you can end up with nested
|
||||
/// AsyncErrors. This unwraps them to find the real originating stack trace.
|
||||
getRealStackTrace(error) {
|
||||
var trace = null;
|
||||
while (error is AsyncError) {
|
||||
trace = error.stackTrace;
|
||||
error = error.error;
|
||||
}
|
||||
|
||||
return trace;
|
||||
}
|
||||
|
|
|
@ -168,12 +168,6 @@ class _Parse extends BaseMatcher {
|
|||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// TODO(nweiz): All the code from here to the next "---..." line was also copied
|
||||
// from pkg/http/test/utils.dart. However, it was also modified to use
|
||||
// getRealError in order to work around issue 7781.
|
||||
|
||||
// TODO(nweiz): remove this once it's built in to unittest
|
||||
/// A matcher for StateErrors.
|
||||
const isStateError = const _StateError();
|
||||
|
@ -184,7 +178,7 @@ const Matcher throwsStateError =
|
|||
|
||||
class _StateError extends TypeMatcher {
|
||||
const _StateError() : super("StateError");
|
||||
bool matches(item, MatchState matchState) => getRealError(item) is StateError;
|
||||
bool matches(item, MatchState matchState) => item is StateError;
|
||||
}
|
||||
|
||||
/// A matcher for HttpExceptions.
|
||||
|
@ -196,8 +190,7 @@ const Matcher throwsHttpException =
|
|||
|
||||
class _HttpException extends TypeMatcher {
|
||||
const _HttpException() : super("HttpException");
|
||||
bool matches(item, MatchState matchState) =>
|
||||
getRealError(item) is HttpException;
|
||||
bool matches(item, MatchState matchState) => item is HttpException;
|
||||
}
|
||||
|
||||
/// A matcher for RedirectLimitExceededExceptions.
|
||||
|
@ -213,7 +206,7 @@ class _RedirectLimitExceededException extends TypeMatcher {
|
|||
super("RedirectLimitExceededException");
|
||||
|
||||
bool matches(item, MatchState matchState) =>
|
||||
getRealError(item) is RedirectLimitExceededException;
|
||||
item is RedirectLimitExceededException;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in a new issue