fix: improve action not found error (#2171)

This commit is contained in:
ChristopherHX 2024-01-28 17:37:19 +01:00 committed by GitHub
parent 424fd5e02b
commit a6ec2c129a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 18 additions and 6 deletions

View File

@ -3,6 +3,7 @@ package runner
import ( import (
"context" "context"
"embed" "embed"
"errors"
"fmt" "fmt"
"io" "io"
"io/fs" "io/fs"
@ -41,11 +42,24 @@ var trampoline embed.FS
func readActionImpl(ctx context.Context, step *model.Step, actionDir string, actionPath string, readFile actionYamlReader, writeFile fileWriter) (*model.Action, error) { func readActionImpl(ctx context.Context, step *model.Step, actionDir string, actionPath string, readFile actionYamlReader, writeFile fileWriter) (*model.Action, error) {
logger := common.Logger(ctx) logger := common.Logger(ctx)
allErrors := []error{}
addError := func(fileName string, err error) {
if err != nil {
allErrors = append(allErrors, fmt.Errorf("failed to read '%s' from action '%s' with path '%s' of step %w", fileName, step.String(), actionPath, err))
} else {
// One successful read, clear error state
allErrors = nil
}
}
reader, closer, err := readFile("action.yml") reader, closer, err := readFile("action.yml")
addError("action.yml", err)
if os.IsNotExist(err) { if os.IsNotExist(err) {
reader, closer, err = readFile("action.yaml") reader, closer, err = readFile("action.yaml")
addError("action.yaml", err)
if os.IsNotExist(err) { if os.IsNotExist(err) {
if _, closer, err2 := readFile("Dockerfile"); err2 == nil { _, closer, err := readFile("Dockerfile")
addError("Dockerfile", err)
if err == nil {
closer.Close() closer.Close()
action := &model.Action{ action := &model.Action{
Name: "(Synthetic)", Name: "(Synthetic)",
@ -90,12 +104,10 @@ func readActionImpl(ctx context.Context, step *model.Step, actionDir string, act
return action, nil return action, nil
} }
} }
return nil, err
} else if err != nil {
return nil, err
} }
} else if err != nil { }
return nil, err if allErrors != nil {
return nil, errors.Join(allErrors...)
} }
defer closer.Close() defer closer.Close()