Error calculator catches NaN and Inf values.

The json generator downstream fails to serialize when the error
estimate is either infinity or not a number. These values may occur
for reports with invalid/missing fields.

Change-Id: Ibec287d8a51ee39b3e349cb6bf6c913a63509301
Reviewed-on: https://fuchsia-review.googlesource.com/c/cobalt/+/470157
Reviewed-by: Alexandre Zani <azani@google.com>
Commit-Queue: Jared Weinstein <jaredweinstein@google.com>
diff --git a/src/bin/config_parser/src/privacy/error_calculator.go b/src/bin/config_parser/src/privacy/error_calculator.go
index 2d13b98..3e85e50 100644
--- a/src/bin/config_parser/src/privacy/error_calculator.go
+++ b/src/bin/config_parser/src/privacy/error_calculator.go
@@ -68,6 +68,10 @@
 		reportType := config.ReportDefinition_ReportType_name[int32(reportType)]
 		return -1, fmt.Errorf("Error estimation is not supported for reports of type %s", reportType)
 	}
+
+	if math.IsNaN(errorEstimate) || math.IsInf(errorEstimate, 0) {
+		return errorEstimate, fmt.Errorf("Error estimation failed to return valid result due to an invalid or missing field.")
+	}
 	return errorEstimate, nil
 }