From baf3bcf48b1c30c83341f9f327343f9623e44c50 Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Tue, 25 Apr 2023 10:09:54 +0800 Subject: [PATCH] avoid using log.Fatal (#1759) --- pkg/model/workflow.go | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/pkg/model/workflow.go b/pkg/model/workflow.go index 68f7b68..e7d43e4 100644 --- a/pkg/model/workflow.go +++ b/pkg/model/workflow.go @@ -58,9 +58,8 @@ func (w *Workflow) On() []string { func (w *Workflow) OnEvent(event string) interface{} { if w.RawOn.Kind == yaml.MappingNode { var val map[string]interface{} - err := w.RawOn.Decode(&val) - if err != nil { - log.Fatal(err) + if !decodeNode(w.RawOn, &val) { + return nil } return val[event] } @@ -85,16 +84,14 @@ func (w *Workflow) WorkflowDispatchConfig() *WorkflowDispatch { } var val map[string]yaml.Node - err := w.RawOn.Decode(&val) - if err != nil { - log.Fatal(err) + if !decodeNode(w.RawOn, &val) { + return nil } var config WorkflowDispatch node := val["workflow_dispatch"] - err = node.Decode(&config) - if err != nil { - log.Fatal(err) + if !decodeNode(node, &config) { + return nil } return &config @@ -128,16 +125,14 @@ func (w *Workflow) WorkflowCallConfig() *WorkflowCall { } var val map[string]yaml.Node - err := w.RawOn.Decode(&val) - if err != nil { - log.Fatal(err) + if !decodeNode(w.RawOn, &val) { + return &WorkflowCall{} } var config WorkflowCall node := val["workflow_call"] - err = node.Decode(&config) - if err != nil { - log.Fatal(err) + if !decodeNode(node, &config) { + return &WorkflowCall{} } return &config @@ -220,9 +215,8 @@ func (j *Job) InheritSecrets() bool { } var val string - err := j.RawSecrets.Decode(&val) - if err != nil { - log.Fatal(err) + if !decodeNode(j.RawSecrets, &val) { + return false } return val == "inherit" @@ -234,9 +228,8 @@ func (j *Job) Secrets() map[string]string { } var val map[string]string - err := j.RawSecrets.Decode(&val) - if err != nil { - log.Fatal(err) + if !decodeNode(j.RawSecrets, &val) { + return nil } return val