Skip to content

Commit b6409a6

Browse files
committed
refactor: simplify and make errors more explicit for Utils#frame method
1 parent fa1a277 commit b6409a6

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ See also the [CHANGELOG](https://github.com/cucumber/cucumber-jvm/blob/master/CH
1313

1414
### Changed
1515

16+
- [Internal] Fix `getLocation` wherever it was wrongly defined. ([#404](https://github.com/cucumber/cucumber-jvm-scala/issues/404))
17+
1618
### Deprecated
1719

1820
### Removed
@@ -24,6 +26,7 @@ See also the [CHANGELOG](https://github.com/cucumber/cucumber-jvm/blob/master/CH
2426
### Changed
2527

2628
- [Internal] Implement `HookDefinition.getHookType` and unimplement `Location.getLocation`. No impact expected for users.
29+
([#401](https://github.com/cucumber/cucumber-jvm-scala/issues/401))
2730

2831
## [8.29.0] (2025-07-15)
2932

cucumber-scala/src/main/scala/io/cucumber/scala/Utils.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@ private[scala] object Utils {
99
val frames = Thread.currentThread().getStackTrace
1010
val currentClass = self.getClass.getName
1111
// Note: the -1 check is here for Scala < 2.13 and objects
12-
frames.reverse
13-
.find(f => f.getClassName == currentClass && f.getLineNumber != -1)
14-
.get
12+
frames.findLast(f =>
13+
f.getClassName == currentClass && f.getLineNumber != -1
14+
) match {
15+
case Some(stackFrame) => stackFrame
16+
case None =>
17+
throw new IllegalStateException(
18+
s"Not able to find stack frame for $currentClass"
19+
)
20+
}
1521
}
1622

1723
}

0 commit comments

Comments
 (0)