From ecf34fcd899fecad9782eea3097a4c38f9fe258b Mon Sep 17 00:00:00 2001 From: Jason Song Date: Fri, 7 Apr 2023 20:12:10 +0800 Subject: Do not crash when parsing an invalid workflow file (#23972) Fix #23658. Related to https://gitea.com/gitea/act/pulls/39 --- modules/actions/workflows.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'modules/actions') diff --git a/modules/actions/workflows.go b/modules/actions/workflows.go index 76c144bb2b..d30982a46b 100644 --- a/modules/actions/workflows.go +++ b/modules/actions/workflows.go @@ -17,8 +17,18 @@ import ( "github.com/nektos/act/pkg/jobparser" "github.com/nektos/act/pkg/model" "github.com/nektos/act/pkg/workflowpattern" + "gopkg.in/yaml.v3" ) +func init() { + model.OnDecodeNodeError = func(node yaml.Node, out interface{}, err error) { + // Log the error instead of panic or fatal. + // It will be a big job to refactor act/pkg/model to return decode error, + // so we just log the error and return empty value, and improve it later. + log.Error("Failed to decode node %v into %T: %v", node, out, err) + } +} + func ListWorkflows(commit *git.Commit) (git.Entries, error) { tree, err := commit.SubTree(".gitea/workflows") if _, ok := err.(git.ErrNotExist); ok { -- cgit v1.2.3