@@ -20,9 +20,12 @@ type (
20
20
)
21
21
22
22
const (
23
- Ignore Policy = iota // Ignore errors and continue
24
- Abort // Abort on first error and return results
25
- Remove // Remove the hook from the list on error and continue
23
+ // Non-strict (permissive) mode.
24
+ PassDown Policy = iota // Pass down the extra keys/values in result to the next plugins
25
+ // Strict mode.
26
+ Ignore // Ignore errors and continue
27
+ Abort // Abort on first error and return results
28
+ Remove // Remove the hook from the list on error and continue
26
29
)
27
30
28
31
const (
@@ -113,7 +116,9 @@ func (h *HookConfig) Run(
113
116
114
117
// This is done to ensure that the return value of the hook is always valid,
115
118
// and that the hook does not return any unexpected values.
116
- if verify (args , result ) {
119
+ // If the verification mode is non-strict (permissive), let the plugin pass
120
+ // extra keys/values to the next plugin in chain.
121
+ if verify (args , result ) || verification == PassDown {
117
122
// Update the last return value with the current result
118
123
returnVal = result
119
124
continue
@@ -122,6 +127,7 @@ func (h *HookConfig) Run(
122
127
// At this point, the hook returned an invalid value, so we need to handle it.
123
128
// The result of the current hook will be ignored, regardless of the policy.
124
129
switch verification {
130
+ // Ignore the result of this plugin, log an error and execute the next hook.
125
131
case Ignore :
126
132
errMsg := fmt .Sprintf (
127
133
"Hook %s (Prio %d) returned invalid value, ignoring" , hookType , prio )
@@ -134,7 +140,7 @@ func (h *HookConfig) Run(
134
140
if idx == 0 {
135
141
returnVal = args
136
142
}
137
- continue
143
+ // Abort execution of the plugins, log the error and return the result of the last hook.
138
144
case Abort :
139
145
errMsg := fmt .Sprintf (
140
146
"Hook %s (Prio %d) returned invalid value, aborting" , hookType , prio )
@@ -147,6 +153,7 @@ func (h *HookConfig) Run(
147
153
return args
148
154
}
149
155
return returnVal
156
+ // Remove the hook from the registry, log the error and execute the next hook.
150
157
case Remove :
151
158
errMsg := fmt .Sprintf (
152
159
"Hook %s (Prio %d) returned invalid value, removing" , hookType , prio )
@@ -159,7 +166,9 @@ func (h *HookConfig) Run(
159
166
if idx == 0 {
160
167
returnVal = args
161
168
}
162
- continue
169
+ case PassDown :
170
+ default :
171
+ returnVal = result
163
172
}
164
173
}
165
174
0 commit comments