Package io.karatelabs.core
Class KarateException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
io.karatelabs.core.KarateException
- All Implemented Interfaces:
Serializable
The exception surfaced to callers (JUnit / surefire, the fluent
Runner API, any
code that catches a Karate failure) when a step fails. It exists to keep the failing
feature-file location attached to the Throwable itself — not just in the
console summary — so a raw stack dump still points the reader at the offending
.feature:line instead of Karate/HTTP-client internals.
Built by forStep(java.lang.Throwable, java.lang.String, int, java.lang.String) at the point a failure escapes to the user (see
ScenarioResult.getErrorWithLocation()), which:
- appends the location to the message on its own line, in the exact
path.feature:lineshape the IDE console filter hyperlinks; and - prepends a synthetic
<feature>stack frame while preserving the original frames below it, so the real origin in the codebase (e.g. a socket read timeout deep in the HTTP client) is not lost.
The undecorated message stays available via getRawMessage() for consumers
(reports, console summary) that render the location separately and don't want it twice.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic KarateExceptionWraperrorso the feature-file location travels with the Throwable.The original error message, without the appendedpath.feature:linelocation.Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Method Details
-
getRawMessage
The original error message, without the appendedpath.feature:linelocation. -
forStep
public static KarateException forStep(Throwable error, String featurePath, int line, String stepText) Wraperrorso the feature-file location travels with the Throwable. Idempotent — an already-wrappedKarateExceptionis returned unchanged so a failure that bubbles through nestedcalls is not decorated repeatedly.- Parameters:
error- the raw step failurefeaturePath- the feature file path, without the trailing:lineline- the 1-indexed line of the failing stepstepText- the offending Gherkin source line (e.g."* match a == 1"), for the synthetic frame
-