question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Change the insertion order of `ExceptionHandlerFunction`

See original GitHub issue

Let’s look at the following example:

 1: ServerBuilder sb = ...
 2: sb.annotatedService()
 3:   .decorator(delegate -> (ctx, req) -> {
 4:       return delegate.serve(ctx, req).mapHeaders(headers -> {
 5:           System.err.println("This isn't called.");
 6:           return headers;
 7:       });
 8:   })
 9:   .exceptionHandlers((ctx, req, cause) -> HttpResponse.of(200))
10:   .build(new Object() {
11:      @Get("/foo")
12:      public HttpResponse foo(String foo) {
13:          throw new IllegalArgumentException();
14:      }
15:  });

The fifth line is not called because the specified exception handler is attached before the decorator so mapHeaders is not applied:

A request flow:
request -> ExceptionHandlerFunction -> decorator -> Request(Response)Converter -> Annotated service

The reason why the ExceptionHandlerFunction is located before the decorator is that we wanted to catch the exception raised in the decorator. However, it has this bypassing problem, and also ExceptionHandlerFunction is not installed with the Request(Response)Converter at the same level which users expect so.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
minwooxcommented, Jun 21, 2022

Thanks for your opinion. 😄

I was just worried that this can be a breaking change.

Yeah, it could be a breaking change so we might be able to change that in 2.0 Or, we can fix it right now if everyone thinks that it’s a bug. 😆

0reactions
ks-yimcommented, Jun 20, 2022

Agree with the direction. I was quite confused with the differentiation between ServerErrorHandler and ExceptionHandlerFunction in the past and the change will make their roles more clear.

I was just worried that this can be a breaking change. cc. @ghkim3221

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java Global Exception Handler - Baeldung
Learn how to globally handle all uncaught exceptions in your Java application.
Read more >
11 PL/SQL Error Handling
11 PL/SQL Error Handling. This chapter explains how to handle PL/SQL compile-time warnings and PL/SQL runtime errors. The latter are called exceptions.
Read more >
Hashmap + Insertion Order - java - Stack Overflow
That's just what happens to occur with the version you're using and the values you're inserting. There's no guarantee it will continue to...
Read more >
Java Catch Multiple Exceptions, Rethrow Exception
Note that this analysis is disabled if you change the catch block argument. Further Reading: Exception Handling in Java.
Read more >
PHP Exception Handling - W3Schools
The code execution will switch to a predefined (custom) exception handler function; Depending on the situation, the handler may then resume the execution...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found