Skip to content

Commit 7646352

Browse files
committed
Add error propagation if matcher fails with error
1 parent b894970 commit 7646352

File tree

1 file changed

+9
-2
lines changed
  • internal/js/modules/k6/browser/common

1 file changed

+9
-2
lines changed

internal/js/modules/k6/browser/common/frame.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,14 +1915,18 @@ func (f *Frame) WaitForNavigation(
19151915
return nil, fmt.Errorf("parsing URL pattern: %w", err)
19161916
}
19171917

1918+
var matcherErr error
19181919
navEvtCh, navEvtCancel := createWaitForEventPredicateHandler(timeoutCtx, f, []string{EventFrameNavigation},
19191920
func(data any) bool {
19201921
if navEvt, ok := data.(*NavigationEvent); ok {
19211922
// Check if the navigation URL matches the pattern
19221923
matched, err := matcher(navEvt.url)
19231924
if err != nil {
1924-
f.log.Error(err)
1925-
return false
1925+
matcherErr = err
1926+
// Return true here even though it's not correct and no match
1927+
// was found. We need this to exit asap so that the error can be
1928+
// propagated to the caller.
1929+
return true
19261930
}
19271931
return matched
19281932
}
@@ -1968,6 +1972,9 @@ func (f *Frame) WaitForNavigation(
19681972
)
19691973
select {
19701974
case evt := <-navEvtCh:
1975+
if matcherErr != nil {
1976+
return nil, matcherErr
1977+
}
19711978
if e, ok := evt.(*NavigationEvent); ok {
19721979
if e.newDocument == nil {
19731980
sameDocNav = true

0 commit comments

Comments
 (0)