Skip to content

Commit 2107a76

Browse files
committed
[core] Correct template error handling when a role is disabled
1 parent fa7f3c0 commit 2107a76

File tree

7 files changed

+23
-9
lines changed

7 files changed

+23
-9
lines changed

configuration/template/fields.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ package template
2727
import (
2828
"bytes"
2929
"encoding/json"
30+
"errors"
3031
"fmt"
3132
"io"
3233
"strings"
@@ -50,7 +51,13 @@ type Sequence map[Stage]Fields
5051
type BuildObjectStackFunc func(stage Stage) map[string]interface{}
5152
type StageCallbackFunc func(stage Stage, err error) error // called after each stage template processing, if err != nil the sequence bails
5253

53-
type RoleDisabledError error
54+
type RoleDisabledError struct {
55+
RolePath string
56+
}
57+
58+
func (e *RoleDisabledError) Error() string {
59+
return fmt.Sprintf("role %s disabled", e.RolePath)
60+
}
5461

5562
func NullCallback(_ Stage, err error) error {
5663
return err
@@ -106,7 +113,8 @@ func (sf Sequence) Execute(confSvc ConfigurationService,
106113
err = fields.Execute(confSvc, parentPath, stagedStack, objectStack, stringTemplateCache, workflowRepo)
107114
err = stageCallback(currentStage, err)
108115
if err != nil {
109-
if _, isRoleDisabled := err.(RoleDisabledError); isRoleDisabled {
116+
var roleDisabledErrorType *RoleDisabledError
117+
if isRoleDisabled := errors.As(err, &roleDisabledErrorType); isRoleDisabled {
110118
return
111119
}
112120

core/integration/odc/plugin.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ func (p *Plugin) ObjectStack(varStack map[string]string) (stack map[string]inter
377377
detectorsSlice, err := p.parseDetectors(pdpDetectorList)
378378
if err != nil {
379379
log.WithField("partition", envId).
380+
WithField("detectorList", pdpDetectorList).
380381
WithField("call", "GenerateEPNWorkflowScript").
381382
Error("cannot parse general detector list")
382383
return
@@ -403,6 +404,7 @@ func (p *Plugin) ObjectStack(varStack map[string]string) (stack map[string]inter
403404
detectorsSlice, err := p.parseDetectors(pdpDetectorListQc)
404405
if err != nil {
405406
log.WithField("partition", envId).
407+
WithField("detectorList", pdpDetectorListQc).
406408
WithField("call", "GenerateEPNWorkflowScript").
407409
Error("cannot parse general detector list")
408410
return
@@ -429,6 +431,7 @@ func (p *Plugin) ObjectStack(varStack map[string]string) (stack map[string]inter
429431
detectorsSlice, err := p.parseDetectors(pdpDetectorListCalib)
430432
if err != nil {
431433
log.WithField("partition", envId).
434+
WithField("detectorList", pdpDetectorListCalib).
432435
WithField("call", "GenerateEPNWorkflowScript").
433436
Error("cannot parse general detector list")
434437
return
@@ -898,6 +901,7 @@ func (p *Plugin) CallStack(data interface{}) (stack map[string]interface{}) {
898901
arguments["detectors"] = strings.Join(detectorsSlice, ",")
899902
} else {
900903
log.WithField("partition", envId).
904+
WithField("detectorList", detectorsSlice).
901905
WithField("call", "Configure").
902906
Warn("cannot parse general detector list")
903907
}

core/workflow/aggregatorrole.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ func (r *aggregatorRole) ProcessTemplates(workflowRepo repos.IRepo, loadSubworkf
127127
UserVars: r.UserVars,
128128
}, r.makeBuildObjectStackFunc(), make(map[string]texttemplate.Template), workflowRepo, MakeDisabledRoleCallback(r))
129129
if err != nil {
130-
if _, isRoleDisabled := err.(template.RoleDisabledError); isRoleDisabled {
130+
var roleDisabledErrorType *template.RoleDisabledError
131+
if isRoleDisabled := errors.As(err, &roleDisabledErrorType); isRoleDisabled {
131132
err = nil // we don't want a disabled role to be considered an error
132133
} else {
133134
return

core/workflow/callrole.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ func (t *callRole) ProcessTemplates(workflowRepo repos.IRepo, _ LoadSubworkflowF
177177
MakeDisabledRoleCallback(t),
178178
)
179179
if err != nil {
180-
if _, isRoleDisabled := err.(template.RoleDisabledError); isRoleDisabled {
180+
var roleDisabledErrorType *template.RoleDisabledError
181+
if isRoleDisabled := errors.As(err, &roleDisabledErrorType); isRoleDisabled {
181182
err = nil // we don't want a disabled role to be considered an error
182183
} else {
183184
return

core/workflow/includerole.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ func (r *includeRole) ProcessTemplates(workflowRepo repos.IRepo, loadSubworkflow
108108
UserVars: r.UserVars,
109109
}, r.makeBuildObjectStackFunc(), make(map[string]texttemplate.Template), workflowRepo, MakeDisabledRoleCallback(r))
110110
if err != nil {
111-
if _, isRoleDisabled := err.(template.RoleDisabledError); isRoleDisabled {
111+
var roleDisabledErrorType *template.RoleDisabledError
112+
if isRoleDisabled := errors.As(err, &roleDisabledErrorType); isRoleDisabled {
112113
err = nil // we don't want a disabled role to be considered an error
113114
} else {
114115
return

core/workflow/roleutils.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
package workflow
2626

2727
import (
28-
"fmt"
29-
3028
"github.com/AliceO2Group/Control/configuration/template"
3129
"github.com/AliceO2Group/Control/core/task/constraint"
3230
)
@@ -105,7 +103,7 @@ func MakeDisabledRoleCallback(r Role) func(stage template.Stage, err error) erro
105103
return func(stage template.Stage, err error) error {
106104
if stage == template.STAGE0 { // only `enabled` has been processed so far
107105
if !r.IsEnabled() {
108-
var rde template.RoleDisabledError = fmt.Errorf("role %s disabled", r.GetPath())
106+
rde := &template.RoleDisabledError{RolePath: r.GetPath()}
109107
return rde
110108
}
111109
}

core/workflow/taskrole.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ func (t *taskRole) ProcessTemplates(workflowRepo repos.IRepo, _ LoadSubworkflowF
164164
UserVars: t.UserVars,
165165
}, t.makeBuildObjectStackFunc(), make(map[string]texttemplate.Template), workflowRepo, MakeDisabledRoleCallback(t))
166166
if err != nil {
167-
if _, isRoleDisabled := err.(template.RoleDisabledError); isRoleDisabled {
167+
var roleDisabledErrorType *template.RoleDisabledError
168+
if isRoleDisabled := errors.As(err, &roleDisabledErrorType); isRoleDisabled {
168169
err = nil // we don't want a disabled role to be considered an error
169170
} else {
170171
return

0 commit comments

Comments
 (0)