Skip to content

Commit

Permalink
Fix nil pointers if a workflow can't be found
Browse files Browse the repository at this point in the history
  • Loading branch information
loicalbertin committed Oct 13, 2020
1 parent 8786efa commit c3a8499
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
9 changes: 7 additions & 2 deletions deployments/workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ package deployments

import (
"context"
"path"
"strings"

"github.com/ystia/yorc/v4/log"
"github.com/ystia/yorc/v4/storage"
"github.com/ystia/yorc/v4/storage/types"
"path"
"strings"

"github.com/pkg/errors"

Expand Down Expand Up @@ -127,6 +128,10 @@ func ResolveWorkflowOutputs(ctx context.Context, deploymentID, workflowName stri
return nil, err
}

if wf == nil {
return nil, errors.Errorf("Can't resolve outputs of workflow %q in deployment %q, workflow definition not found", workflowName, deploymentID)
}

outputs := make(map[string]*TOSCAValue)
for outputName, outputDef := range wf.Outputs {
dataType := getTypeFromParamDefinition(ctx, &outputDef)
Expand Down
7 changes: 6 additions & 1 deletion rest/dep_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ func (s *Server) newWorkflowHandler(w http.ResponseWriter, r *http.Request) {
if err != nil {
log.Panic(err)
}

if wf == nil {
log.Panic(errors.Errorf("Can't check inputs of workflow %q in deployment %q, workflow definition not found", workflowName, deploymentID))
}
for inputName, def := range wf.Inputs {
// A property is considered as required by default, unless def.Required
// is set to false
Expand Down Expand Up @@ -205,5 +207,8 @@ func (s *Server) getWorkflowHandler(w http.ResponseWriter, r *http.Request) {
if err != nil {
log.Panic(err)
}
if wf == nil {
log.Panic(errors.Errorf("Can't retrieve workflow %q in deployment %q, workflow definition not found", workflowName, deploymentID))
}
encodeJSONResponse(w, r, Workflow{Name: workflowName, Workflow: *wf})
}
4 changes: 4 additions & 0 deletions tasks/workflow/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func BuildWorkFlow(ctx context.Context, deploymentID, wfName string) (map[string
return nil, err
}

if wf == nil {
return nil, errors.Errorf("Can't build workflow %q in deployment %q, workflow definition not found", wfName, deploymentID)
}

if wf.Steps == nil || len(wf.Steps) == 0 {
return nil, deployments.NewInconsistentDeploymentError(deploymentID)
}
Expand Down
4 changes: 4 additions & 0 deletions tasks/workflow/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,10 @@ func (s *step) getActivityInputParameters(ctx context.Context, activity builder.
return nil, err
}

if wf == nil {
return nil, errors.Errorf("Can't retrieve inputs for an activity of workflow %q in deployment %q, workflow definition not found", workflowName, deploymentID)
}

for inputName, propDef := range wf.Inputs {

if _, ok := result[inputName]; ok {
Expand Down

0 comments on commit c3a8499

Please sign in to comment.