Skip to content

Skip stack trace capture in HttpProblem and guard ExceptionMapperBase against toProblem failures - #665

Open
phillip-kruger wants to merge 1 commit into
quarkiverse:mainfrom
phillip-kruger:exception-pipeline-resilience
Open

Skip stack trace capture in HttpProblem and guard ExceptionMapperBase against toProblem failures#665
phillip-kruger wants to merge 1 commit into
quarkiverse:mainfrom
phillip-kruger:exception-pipeline-resilience

Conversation

@phillip-kruger

@phillip-kruger phillip-kruger commented Aug 4, 2026

Copy link
Copy Markdown
Member

Closes #669
Closes #670

HttpProblem extends RuntimeException but is used as a structured error container, not for diagnostics. Every construction was capturing a full stack trace - wasted CPU, especially for high-volume 4xx responses. Overriding fillInStackTrace() eliminates this overhead (the existing JMH benchmark can measure the improvement).

Separately, ExceptionMapperBase.toResponse() had no protection if a subclass's toProblem() threw an exception or returned null. The original mapped problem would be lost and the user would get an uncontrolled error instead of a proper application/problem+json response. Now the method catches exceptions and handles null by falling back to a generic 500 problem, logging the failure at ERROR level.

… against toProblem failures

HttpProblem is used as a structured error container, not for diagnostics.
Overriding fillInStackTrace() avoids wasted CPU on every construction,
especially for high-volume 4xx responses.

ExceptionMapperBase.toResponse() now catches exceptions from toProblem()
and handles null returns by falling back to a generic 500 response,
ensuring the pipeline always produces valid application/problem+json.
@gsmet
gsmet force-pushed the exception-pipeline-resilience branch from 42a7bfe to 8d3ab90 Compare August 5, 2026 08:04
@lwitkowski

Copy link
Copy Markdown
Collaborator

I like it. One consequence worth IMO calling out:

HttpProblem is intentionally throwable from services/controllers. Skipping fillInStackTrace() is fine for the common 4xx control-flow case (ProblemLogger already logs those without the throwable). For thrown 5xx HttpProblems, though, context.cause is the problem itself, so error logs lose the throw-site stack.

Maybe it's worth a short note in the README, something along the lines: treat thrown HttpProblem as control flow; for diagnosable server errors, prefer throwing a real exception and mapping it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ExceptionMapperBase.toResponse has no protection if toProblem() throws or returns null HttpProblem captures a full stack trace on every construction

2 participants