9
9
10
10
"github.com/Masterminds/sprig"
11
11
"github.com/juju/errors"
12
- "github.com/robertkrimen/otto"
13
12
"github.com/ovh/utask"
13
+ "github.com/robertkrimen/otto"
14
14
)
15
15
16
16
// keys to store/retrieve data from a Values struct
@@ -26,6 +26,7 @@ const (
26
26
OutputKey = "output"
27
27
MetadataKey = "metadata"
28
28
ChildrenKey = "children"
29
+ ErrorKey = "error"
29
30
)
30
31
31
32
// Values is a container for all the live data of a running task
@@ -124,6 +125,21 @@ func (v *Values) UnsetChildren(stepName string) {
124
125
v .unsetStepData (stepName , ChildrenKey )
125
126
}
126
127
128
+ // GetError returns the error resulting from a failed step
129
+ func (v * Values ) GetError (stepName string ) interface {} {
130
+ return v .getStepData (stepName , ErrorKey )
131
+ }
132
+
133
+ // SetChildren stores the error resulting from a failed step
134
+ func (v * Values ) SetError (stepName string , value interface {}) {
135
+ v .setStepData (stepName , ErrorKey , value )
136
+ }
137
+
138
+ // UnsetChildren empties the error from a failed step
139
+ func (v * Values ) UnsetError (stepName string ) {
140
+ v .unsetStepData (stepName , ErrorKey )
141
+ }
142
+
127
143
func (v * Values ) getStepData (stepName , field string ) interface {} {
128
144
stepmap := v .m [StepKey ].(map [string ]interface {})
129
145
if stepmap [stepName ] == nil {
@@ -213,6 +229,9 @@ func (v *Values) Apply(templateStr string, item interface{}, stepName string) ([
213
229
214
230
v .SetChildren (utask .This , v .GetChildren (stepName ))
215
231
defer v .UnsetChildren (utask .This )
232
+
233
+ v .SetError (utask .This , v .GetError (stepName ))
234
+ defer v .UnsetError (utask .This )
216
235
}
217
236
218
237
err = tmpl .Execute (b , v .m )
0 commit comments