From c32d1387ab9a6cba7a4f9849dce1d6df63f5a173 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Mon, 4 May 2020 09:10:20 -0700 Subject: [PATCH] Fix overly specific detection of non-UTF8 files in analyzer bot. (#56295) An upcoming Dart SDK change (https://github.com/dart-lang/sdk/commit/fa2fd41166db35afa4777e63f900e83d25709c5c) changes the precise text of the exception generated by `utf8.decode` if a non-UTF8 file is found. This is causing a breakage in the Dart team's `flutter-analyze` bot (and will presumably cause a breakage in the corresponding Flutter bot as soon as this change is rolled into Flutter). To avoid this breakage, the bot shouldn't rely on the exact exception text; it is sufficient to simply catch a FormatException. --- dev/bots/analyze.dart | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/dev/bots/analyze.dart b/dev/bots/analyze.dart index 4376bc7c6c7c..71d4647d9e4c 100644 --- a/dev/bots/analyze.dart +++ b/dev/bots/analyze.dart @@ -1086,13 +1086,9 @@ Future verifyNoBinaries(String workingDirectory, { Set grandfathe try { utf8.decode(bytes); } on FormatException catch (error) { - if (error.message.startsWith('Bad UTF-8 encoding ')) { - final Digest digest = sha256.convert(bytes); - if (!grandfatheredBinaries.contains(Hash256.fromDigest(digest))) - problems.add('${file.path}:${error.offset}: file is not valid UTF-8'); - } else { - rethrow; - } + final Digest digest = sha256.convert(bytes); + if (!grandfatheredBinaries.contains(Hash256.fromDigest(digest))) + problems.add('${file.path}:${error.offset}: file is not valid UTF-8'); } } if (problems.isNotEmpty) {