Skip to content

Commit 29c127e

Browse files
committed
Clean up avoid_type_to_string suppressions
1 parent f9af233 commit 29c127e

7 files changed

Lines changed: 54 additions & 8 deletions

File tree

dev/bots/prepare_package/common.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ enum Branch { beta, stable, master, main }
2222

2323
/// Exception class for when a process fails to run, so we can catch
2424
/// it and provide something more readable than a stack trace.
25-
class PreparePackageException implements Exception {
25+
final class PreparePackageException implements Exception {
2626
PreparePackageException(this.message, [this.result]);
2727

2828
final String message;
@@ -31,8 +31,7 @@ class PreparePackageException implements Exception {
3131

3232
@override
3333
String toString() {
34-
// ignore: avoid_type_to_string
35-
var output = runtimeType.toString();
34+
var output = '$PreparePackageException';
3635
output += ': $message';
3736
final String stderr = result?.stderr as String? ?? '';
3837
if (stderr.isNotEmpty) {

dev/bots/test/prepare_package_test.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ import 'common.dart';
2121

2222
void main() {
2323
const testRef = 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef';
24+
25+
test('PreparePackageException string includes class name and stderr', () {
26+
final exception = PreparePackageException(
27+
'failed to prepare package',
28+
ProcessResult(0, 1, '', 'stderr details'),
29+
);
30+
31+
expect(
32+
exception.toString(),
33+
'PreparePackageException: failed to prepare package:\nstderr details',
34+
);
35+
});
36+
2437
test('Throws on missing executable', () async {
2538
// Uses a *real* process manager, since we want to know what happens if
2639
// it can't find an executable.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:io' show ProcessResult;
6+
7+
import '../unpublish_package.dart';
8+
import 'common.dart';
9+
10+
void main() {
11+
test('UnpublishException string includes class name and stderr', () {
12+
final exception = UnpublishException(
13+
'failed to unpublish package',
14+
ProcessResult(0, 1, '', 'stderr details'),
15+
);
16+
17+
expect(
18+
exception.toString(),
19+
'UnpublishException: failed to unpublish package:\nstderr details',
20+
);
21+
});
22+
}

dev/bots/unpublish_package.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const String baseUrl = 'https://storage.googleapis.com/flutter_infra_release';
3030

3131
/// Exception class for when a process fails to run, so we can catch
3232
/// it and provide something more readable than a stack trace.
33-
class UnpublishException implements Exception {
33+
final class UnpublishException implements Exception {
3434
UnpublishException(this.message, [this.result]);
3535

3636
final String message;
@@ -39,8 +39,7 @@ class UnpublishException implements Exception {
3939

4040
@override
4141
String toString() {
42-
// ignore: avoid_type_to_string
43-
var output = runtimeType.toString();
42+
var output = '$UnpublishException';
4443
output += ': $message';
4544
final String stderr = result?.stderr as String? ?? '';
4645
if (stderr.isNotEmpty) {

packages/flutter_tools/lib/runner.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ Future<int> _handleToolErrorImpl(
243243
return exitWithHooks(1, shutdownHooks: shutdownHooks);
244244
}
245245

246+
// Flutter tool crash analytics benefits from the concrete Dart error type.
247+
// The tool is not obfuscated, and collapsing unknown types to Object loses useful signal.
246248
// ignore: avoid_type_to_string
247249
globals.analytics.send(Event.exception(exception: error.runtimeType.toString()));
248250

packages/flutter_tools/lib/src/reporting/github_template.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ class GitHubTemplateCreator {
6868
// Force comma separator to standardize.
6969
return 'String: <${NumberFormat(null, 'en_US').format(error.length)} characters>';
7070
}
71-
// Exception, other.
72-
return error.runtimeType.toString(); // ignore: avoid_type_to_string
71+
// Tool crash issue templates benefit from the concrete Dart error type.
72+
// The tool is not obfuscated, and collapsing unknown types loses useful signal.
73+
// ignore: avoid_type_to_string
74+
return error.runtimeType.toString();
7375
}
7476

7577
/// GitHub URL to present to the user containing encoded suggested template.

packages/flutter_tools/test/general.shard/github_template_test.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ void main() {
167167
'_Exception',
168168
);
169169
});
170+
171+
testWithoutContext('custom Exception', () {
172+
expect(GitHubTemplateCreator.sanitizedCrashException(FakeException()), 'FakeException');
173+
});
170174
});
171175

172176
group('new issue template URL', () {
@@ -302,3 +306,8 @@ class FakeError extends Error {
302306
@override
303307
String toString() => 'PII to ignore';
304308
}
309+
310+
class FakeException implements Exception {
311+
@override
312+
String toString() => 'PII to ignore';
313+
}

0 commit comments

Comments
 (0)