From e07c3af9abd1dd8be90ad77252b4f8d3af5996ef Mon Sep 17 00:00:00 2001 From: Moshe Immermam Date: Wed, 4 Sep 2024 14:24:18 +0300 Subject: [PATCH] chore: support playbook action failures without errors --- models/playbooks.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/models/playbooks.go b/models/playbooks.go index 39546acb..c8589441 100644 --- a/models/playbooks.go +++ b/models/playbooks.go @@ -420,19 +420,24 @@ func (p PlaybookRunAction) Start(db *gorm.DB) error { } func (p PlaybookRunAction) Fail(db *gorm.DB, result any, err error) error { - if o, ok := oops.AsOops(err); ok { - result = map[string]any{ - "result": result, - "error": o.ToMap(), - } - } - if err := p.Update(db, map[string]any{ - "error": err.Error(), + updates := map[string]any{ "result": marshallResult(result), "start_time": gorm.Expr("CASE WHEN start_time IS NULL THEN CLOCK_TIMESTAMP() ELSE start_time END"), "end_time": gorm.Expr("CLOCK_TIMESTAMP()"), "status": PlaybookActionStatusFailed, - }); err != nil { + } + + if err != nil { + if o, ok := oops.AsOops(err); ok { + updates["result"] = map[string]any{ + "result": result, + "error": o.ToMap(), + } + } + updates["error"] = err.Error() + } + + if err := p.Update(db, updates); err != nil { return err }