Class KarateException

All Implemented Interfaces:
Serializable

public class KarateException extends RuntimeException
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:line shape 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 Details

    • getRawMessage

      public String getRawMessage()
      The original error message, without the appended path.feature:line location.
    • forStep

      public static KarateException forStep(Throwable error, String featurePath, int line, String stepText)
      Wrap error so the feature-file location travels with the Throwable. Idempotent — an already-wrapped KarateException is returned unchanged so a failure that bubbles through nested calls is not decorated repeatedly.
      Parameters:
      error - the raw step failure
      featurePath - the feature file path, without the trailing :line
      line - the 1-indexed line of the failing step
      stepText - the offending Gherkin source line (e.g. "* match a == 1"), for the synthetic frame