github.com/nektos/act@v0.2.63/pkg/common/job_error.go (about) 1 package common 2 3 import ( 4 "context" 5 ) 6 7 type jobErrorContextKey string 8 9 const jobErrorContextKeyVal = jobErrorContextKey("job.error") 10 11 // JobError returns the job error for current context if any 12 func JobError(ctx context.Context) error { 13 val := ctx.Value(jobErrorContextKeyVal) 14 if val != nil { 15 if container, ok := val.(map[string]error); ok { 16 return container["error"] 17 } 18 } 19 return nil 20 } 21 22 func SetJobError(ctx context.Context, err error) { 23 ctx.Value(jobErrorContextKeyVal).(map[string]error)["error"] = err 24 } 25 26 // WithJobErrorContainer adds a value to the context as a container for an error 27 func WithJobErrorContainer(ctx context.Context) context.Context { 28 container := map[string]error{} 29 return context.WithValue(ctx, jobErrorContextKeyVal, container) 30 }