@@ -62,6 +62,7 @@ type SubstituteFunc func(string, Mapping) (string, bool, error)
62
62
// It accepts additional substitute function.
63
63
func SubstituteWith (template string , mapping Mapping , pattern * regexp.Regexp , subsFuncs ... SubstituteFunc ) (string , error ) {
64
64
var outerErr error
65
+ var returnErr error
65
66
66
67
result := pattern .ReplaceAllStringFunc (template , func (substring string ) string {
67
68
_ , subsFunc := getSubstitutionFunctionForTemplate (substring )
@@ -91,6 +92,9 @@ func SubstituteWith(template string, mapping Mapping, pattern *regexp.Regexp, su
91
92
92
93
if substitution == "" {
93
94
outerErr = & InvalidTemplateError {Template : template }
95
+ if returnErr == nil {
96
+ returnErr = outerErr
97
+ }
94
98
return ""
95
99
}
96
100
@@ -101,6 +105,9 @@ func SubstituteWith(template string, mapping Mapping, pattern *regexp.Regexp, su
101
105
)
102
106
value , applied , outerErr = subsFunc (substitution , mapping )
103
107
if outerErr != nil {
108
+ if returnErr == nil {
109
+ returnErr = outerErr
110
+ }
104
111
return ""
105
112
}
106
113
if applied {
@@ -119,7 +126,7 @@ func SubstituteWith(template string, mapping Mapping, pattern *regexp.Regexp, su
119
126
return value
120
127
})
121
128
122
- return result , outerErr
129
+ return result , returnErr
123
130
}
124
131
125
132
func getSubstitutionFunctionForTemplate (template string ) (string , SubstituteFunc ) {
0 commit comments