Check for an exception when asking if the Platform is windows

Change-Id: I4c247f5ae38e724d32e9db383817efa57047eea4
Reviewed-on: https://dart-review.googlesource.com/71901
Commit-Queue: Alan Knight <alanknight@google.com>
Reviewed-by: Jenny Messerly <jmesserly@google.com>
This commit is contained in:
Alan Knight 2018-08-30 22:17:45 +00:00 committed by commit-bot@chromium.org
parent ce117b0f92
commit e3a063319d

View file

@ -212,7 +212,17 @@ List<String> filterUnknownArguments(List<String> args, ArgParser parser) {
/// Convert a [source] string to a Uri, where the source may be a
/// dart/file/package URI or a local win/mac/linux path.
Uri sourcePathToUri(String source, {bool windows}) {
windows ??= Platform.isWindows;
if (windows == null) {
// Running on the web the Platform check will fail, and we can't use
// fromEnvironment because internally it's set to true for dart.library.io.
// So just catch the exception and if it fails then we're definitely not on
// Windows.
try {
windows = Platform.isWindows;
} catch (e) {
windows = false;
}
}
if (windows) {
source = source.replaceAll("\\", "/");
}