From 950b000116dc27a3a71969459f41c994fba4f5f2 Mon Sep 17 00:00:00 2001 From: David Elie-Dit-Cosaque Date: Mon, 22 Jan 2024 16:09:55 -0600 Subject: [PATCH] Addressing comments from b. Crochet --- certification/results.go | 11 ++++++++++- internal/engine/engine.go | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/certification/results.go b/certification/results.go index 9a9496aa..d1e04ea7 100644 --- a/certification/results.go +++ b/certification/results.go @@ -15,7 +15,7 @@ type Result struct { // Err contains the error a check itself throws if it failed to run. // If populated, the expectation is that this Result is in the // Results{}.Errors slice. - Err error + err error } type Results struct { @@ -28,3 +28,12 @@ type Results struct { Errors []Result Warned []Result } + +func (r Result) Error() error { + return r.err +} + +func (r *Result) WithError(err error) *Result { + r.err = err + return r +} diff --git a/internal/engine/engine.go b/internal/engine/engine.go index 3cfb5f3c..0ec78f86 100644 --- a/internal/engine/engine.go +++ b/internal/engine/engine.go @@ -231,7 +231,8 @@ func (c *craneEngine) ExecuteChecks(ctx context.Context) error { if err != nil { logger.WithValues("result", "ERROR", "err", err.Error()).Info("check completed", "check", executedCheck.Name()) - c.results.Errors = appendUnlessOptional(c.results.Errors, certification.Result{Check: executedCheck, ElapsedTime: checkElapsedTime, Err: err}) + result := certification.Result{Check: executedCheck, ElapsedTime: checkElapsedTime} + c.results.Errors = appendUnlessOptional(c.results.Errors, *result.WithError(err)) continue }