Unverified Commit 16c0a3d7 authored by Abhishek Ghaskata's avatar Abhishek Ghaskata Committed by GitHub

Migrate task_result to null safety (#84939)

parent a8232dd7
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:convert'; import 'dart:convert';
import 'dart:io'; import 'dart:io';
...@@ -25,13 +23,13 @@ class TaskResult { ...@@ -25,13 +23,13 @@ class TaskResult {
: succeeded = true { : succeeded = true {
const JsonEncoder prettyJson = JsonEncoder.withIndent(' '); const JsonEncoder prettyJson = JsonEncoder.withIndent(' ');
if (benchmarkScoreKeys != null) { if (benchmarkScoreKeys != null) {
for (final String key in benchmarkScoreKeys) { for (final String key in benchmarkScoreKeys!) {
if (!data.containsKey(key)) { if (!data!.containsKey(key)) {
throw 'Invalid benchmark score key "$key". It does not exist in task ' throw 'Invalid benchmark score key "$key". It does not exist in task '
'result data ${prettyJson.convert(data)}'; 'result data ${prettyJson.convert(data)}';
} else if (data[key] is! num) { } else if (data![key] is! num) {
throw 'Invalid benchmark score for key "$key". It is expected to be a num ' throw 'Invalid benchmark score for key "$key". It is expected to be a num '
'but was ${(data[key] as Object).runtimeType}: ${prettyJson.convert(data[key])}'; 'but was ${(data![key] as Object).runtimeType}: ${prettyJson.convert(data![key])}';
} }
} }
} }
...@@ -53,8 +51,8 @@ class TaskResult { ...@@ -53,8 +51,8 @@ class TaskResult {
factory TaskResult.fromJson(Map<String, dynamic> json) { factory TaskResult.fromJson(Map<String, dynamic> json) {
final bool success = json['success'] as bool; final bool success = json['success'] as bool;
if (success) { if (success) {
final List<String> benchmarkScoreKeys = (json['benchmarkScoreKeys'] as List<dynamic> ?? <String>[]).cast<String>(); final List<String> benchmarkScoreKeys = (json['benchmarkScoreKeys'] as List<dynamic>? ?? <String>[]).cast<String>();
final List<String> detailFiles = (json['detailFiles'] as List<dynamic> ?? <String>[]).cast<String>(); final List<String> detailFiles = (json['detailFiles'] as List<dynamic>? ?? <String>[]).cast<String>();
return TaskResult.success(json['data'] as Map<String, dynamic>, return TaskResult.success(json['data'] as Map<String, dynamic>,
benchmarkScoreKeys: benchmarkScoreKeys, benchmarkScoreKeys: benchmarkScoreKeys,
detailFiles: detailFiles, detailFiles: detailFiles,
...@@ -76,15 +74,15 @@ class TaskResult { ...@@ -76,15 +74,15 @@ class TaskResult {
final bool succeeded; final bool succeeded;
/// Task-specific JSON data /// Task-specific JSON data
final Map<String, dynamic> data; final Map<String, dynamic>? data;
/// Files containing detail on the run (e.g. timeline trace files) /// Files containing detail on the run (e.g. timeline trace files)
final List<String> detailFiles; final List<String>? detailFiles;
/// Keys in [data] that store scores that will be submitted to Cocoon. /// Keys in [data] that store scores that will be submitted to Cocoon.
/// ///
/// Each key is also part of a benchmark's name tracked by Cocoon. /// Each key is also part of a benchmark's name tracked by Cocoon.
final List<String> benchmarkScoreKeys; final List<String>? benchmarkScoreKeys;
/// Whether the task failed. /// Whether the task failed.
bool get failed => !succeeded; bool get failed => !succeeded;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment