Skip to content

Commit

Permalink
Replace an NPE with a human-readable error message. (#3831)
Browse files Browse the repository at this point in the history
See flutter/flutter#152194 where I got befuddling error messages:

```txt
Unhandled exception:
Null check operator used on a null value
#0      DeviceLabTestOwner.getTestOwnership (package:cocoon_service/src/request_handlers/test_ownership.dart:60:59)
#1      getTestOwnership (package:cocoon_service/src/request_handlers/flaky_handler_utils.dart:301:20)
#2      validateOwnership (package:cocoon_service/src/foundation/utils.dart:225:27)
#3      remoteCheck (file:///b/s/w/ir/x/w/cocoon/app_dart/bin/validate_task_ownership.dart:31:40)
<asynchronous suspension>
#4      main (file:///b/s/w/ir/x/w/cocoon/app_dart/bin/validate_task_ownership.dart:63:23)
<asynchronous suspension>
```
  • Loading branch information
matanlurey authored Jul 24, 2024
1 parent 637bca4 commit 6239d77
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion app_dart/lib/src/request_handlers/test_ownership.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,19 @@ class DeviceLabTestOwner implements TestOwner {
) {
String? owner;
Team? team;
final String testName = target.properties['task_name']!;
final String? testName = target.properties['task_name'];
if (testName == null) {
throw FormatException(
'The field "task_name" is required in the target properties for any '
'test that runs in the device lab. If you are seeing this error, your '
'.ci.yaml target is missing this field *OR* the target was not '
'intended to run in the device lab, and "devicelab" should be removed '
'from the "tags" field.\n\n'
'See <https://github.com/flutter/cocoon/blob/main/CI_YAML.md> for more '
'information on how to configure your .ci.yaml file.',
target.properties,
);
}
// The format looks like this:
// /dev/devicelab/bin/tasks/dart_plugin_registry_test.dart @stuartmorgan @flutter/plugin
final RegExpMatch? match = devicelabTestOwners.firstMatch(testOwnersContent);
Expand Down

0 comments on commit 6239d77

Please sign in to comment.