Skip to content

Commit

Permalink
fix: re-use variable placeholder (#764)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aenimus authored Apr 3, 2024
1 parent f17b9ce commit f5018fb
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,8 @@ func (p *Planner[T]) extractEventSubject(ref int, subject string) (string, error
Path: []string{string(variableName)},
Renderer: renderer,
}
variablePlaceHolder, exists := p.variables.AddVariable(contextVariable) // $$0$$
if exists {
return "", fmt.Errorf("context variable \"%s\" already exists", variableName)
}
// We need to replace the template literal with the variable placeholder
// We need to replace the template literal with the variable placeholder (and reuse if it already exists)
variablePlaceHolder, _ := p.variables.AddVariable(contextVariable) // $$0$$
return eventSubjectRegex.ReplaceAllLiteralString(subject, variablePlaceHolder), nil
}

Expand Down Expand Up @@ -427,7 +424,7 @@ func (p *Planner[T]) handleSubscriptionEvent(ref int, eventConfiguration *EventC
for _, rawSubject := range eventConfiguration.Subjects {
extractedSubject, err := p.extractEventSubject(ref, rawSubject)
if err != nil {
p.visitor.Walker.StopWithInternalErr(fmt.Errorf("could not extract subscriptionevent subjects: %w", err))
p.visitor.Walker.StopWithInternalErr(fmt.Errorf("could not extract subscription event subjects: %w", err))
return
}
extractedSubjects = append(extractedSubjects, extractedSubject)
Expand Down

0 comments on commit f5018fb

Please sign in to comment.