Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JBoss Logging and log exceptions when calling the thread context #197

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kabir
Copy link
Contributor

@kabir kabir commented Aug 21, 2020

providers

if (t instanceof RuntimeException) {
throw (RuntimeException) t;
}
throw new RuntimeException(t);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (t instanceof RuntimeException) {
throw (RuntimeException) t;
}
throw new RuntimeException(t);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

}
throw new RuntimeException(t);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

@FroMage
Copy link
Contributor

FroMage commented Aug 21, 2020

LGTM, except the wrapping of Throwable, as explained.

Copy link
Contributor

@manovotn manovotn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kabir
Copy link
Contributor Author

kabir commented Aug 21, 2020

Updated. The rethrow is a nice trick!

@FroMage
Copy link
Contributor

FroMage commented Aug 21, 2020

2020-08-21T12:35:54.6844857Z [ERROR] Failed to execute goal net.revelc.code.formatter:formatter-maven-plugin:2.12.1:validate (default-cli) on project smallrye-context-propagation: File '/home/runner/work/smallrye-context-propagation/smallrye-context-propagation/core/src/main/java/io/smallrye/context/impl/ActiveContextState.java' has not been previously formatted.  Please format file and commit before running validation! -> [Help 1]

}
}

public static <T extends Throwable> void rethrow(Throwable t) throws T {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slight nitpicking but wouldn't it be cleaner to have some util class containing this method instead of placing it here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's what I have in SmallRye Fault Tolerance:

public class SneakyThrow {
    private SneakyThrow() {
    }

    /**
     * This method can and should be used as part of a {@code throw} statement,
     * such as: {@code throw sneakyThrow(exception);}. It is guaranteed to never return normally,
     * and this style of usage makes sure that the Java compiler is aware of that.
     */
    @SuppressWarnings("unchecked")
    public static <E extends Throwable> RuntimeException sneakyThrow(Throwable e) throws E {
        throw (E) e;
    }
}

Note the comment about usage. It's often nice (and I made it a rule for myself) to use the method like throw sneakyThrow(...), so that javac's control flow analysis knows that this is actually a throw.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's rather nice, thanks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah, SneakyThrow is a really good util class name :-D

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not my invention :-) I think it's in Lombok, and was most likely used before that too.

manovotn
manovotn previously approved these changes Aug 21, 2020
@manovotn
Copy link
Contributor

@kabir also, the formatter plugin dislikes you ;-)

[ERROR] Failed to execute goal net.revelc.code.formatter:formatter-maven-plugin:2.12.1:validate (default-cli) on project smallrye-context-propagation: File '/home/runner/work/smallrye-context-propagation/smallrye-context-propagation/core/src/main/java/io/smallrye/context/impl/ActiveContextState.java' has not been previously formatted.  Please format file and commit before running validation! -> [Help 1]

@kabir
Copy link
Contributor Author

kabir commented Aug 21, 2020

Formatted and util made

Copy link
Contributor

@FroMage FroMage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@FroMage
Copy link
Contributor

FroMage commented Aug 21, 2020

TBH I do wonder why we have to log an exception we rethrow, shouldn't it be logged by the caller?

@kabir
Copy link
Contributor Author

kabir commented Aug 21, 2020

@FroMage AFAICT it gets swallowed by the CP plumbing

@FroMage
Copy link
Contributor

FroMage commented Aug 21, 2020

@FroMage AFAICT it gets swallowed by the CP plumbing

If we have exception-swallowing in SR-CP I want to know where and fix it. Do you have stack traces?

@kabir
Copy link
Contributor Author

kabir commented Aug 24, 2020

TBH I do wonder why we have to log an exception we rethrow, shouldn't it be logged by the caller?

We don't really know who the caller is. In my case it was Reactive Messaging which makes a load of these calls, and it was not logged there which made tracking down why streams suddenly stop emitting data tricky. Although it sounds like we've decided that RM using CP is a bug, there could be other complex things calling this. To me it makes sense having it centralised in CP.

Base automatically changed from master to main March 23, 2021 15:09
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.

4 participants