@@ -62,6 +62,7 @@ type SubstituteFunc func(string, Mapping) (string, bool, error)
6262// It accepts additional substitute function.
6363func SubstituteWith (template string , mapping Mapping , pattern * regexp.Regexp , subsFuncs ... SubstituteFunc ) (string , error ) {
6464 var outerErr error
65+ var returnErr error
6566
6667 result := pattern .ReplaceAllStringFunc (template , func (substring string ) string {
6768 _ , subsFunc := getSubstitutionFunctionForTemplate (substring )
@@ -91,6 +92,9 @@ func SubstituteWith(template string, mapping Mapping, pattern *regexp.Regexp, su
9192
9293 if substitution == "" {
9394 outerErr = & InvalidTemplateError {Template : template }
95+ if returnErr == nil {
96+ returnErr = outerErr
97+ }
9498 return ""
9599 }
96100
@@ -101,6 +105,9 @@ func SubstituteWith(template string, mapping Mapping, pattern *regexp.Regexp, su
101105 )
102106 value , applied , outerErr = subsFunc (substitution , mapping )
103107 if outerErr != nil {
108+ if returnErr == nil {
109+ returnErr = outerErr
110+ }
104111 return ""
105112 }
106113 if applied {
@@ -119,7 +126,7 @@ func SubstituteWith(template string, mapping Mapping, pattern *regexp.Regexp, su
119126 return value
120127 })
121128
122- return result , outerErr
129+ return result , returnErr
123130}
124131
125132func getSubstitutionFunctionForTemplate (template string ) (string , SubstituteFunc ) {
0 commit comments