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

INTERNAL: stacktrace all exceptions #840

Merged
merged 1 commit into from
Nov 25, 2024
Merged

Conversation

oliviarla
Copy link
Collaborator

@oliviarla oliviarla commented Nov 20, 2024

πŸ”— Related Issue

⌨️ What I did

  • CompositeException 객체의 printStackTrace() λ©”μ„œλ“œλ₯Ό 톡해 μ˜ˆμ™Έμ— λŒ€ν•œ μŠ€νƒμ„ 확인할 λ•Œ, μ•„λž˜μ™€ 같이 각각의 μ˜ˆμ™Έλ“€μ— λŒ€ν•œ stacktraceκ°€ μ°νžˆλ„λ‘ ν•©λ‹ˆλ‹€.

@oliviarla oliviarla requested a review from uhm0311 November 20, 2024 10:48
@uhm0311
Copy link
Collaborator

uhm0311 commented Nov 20, 2024

μ•„λž˜μ™€ 같이 λ‹¨μˆœν•˜κ²Œ ν•˜λ©΄ μ–΄λ–»κ²Œ λ˜λ‚˜μš”?

@Override
public synchronized Throwable getCause() {
  return !exceptions.isEmpty() ? exceptions.get(0) : null;
}

@Override
public StackTraceElement[] getStackTrace() {
  return exceptions.stream()
          .map(Throwable::getStackTrace)
          .flatMap(Arrays::stream)
          .toArray(StackTraceElement[]::new);
}

@Override
public void printStackTrace(PrintStream s) {
  exceptions.forEach((e) -> e.printStackTrace(s));
}

@Override
public void printStackTrace(PrintWriter s) {
  exceptions.forEach((e) -> e.printStackTrace(s));
}

@jhpark816
Copy link
Collaborator

@oliviarla
κΈ°μ‘΄μ—λŠ” stacktraceκ°€ μ–΄λ–»κ²Œ 좜λ ₯λ˜μ—ˆλ‚˜μš”?

@oliviarla
Copy link
Collaborator Author

@uhm0311
μ•„λž˜μ™€ 같이 μŠ€νƒνŠΈλ ˆμ΄μŠ€κ°€ 찍히게 λ©λ‹ˆλ‹€. ν˜„μž¬ κ΅¬ν˜„κ³Ό λ‹€λ₯Έ 점은 getCause() λ©”μ„œλ“œ 호좜 μ‹œμ— λ°˜ν™˜λ˜λŠ” Throwable에 전체 μ˜ˆμ™Έμ— λŒ€ν•œ λ©”μ‹œμ§€λ₯Ό 담을지 말지 μž…λ‹ˆλ‹€. μ €λŠ” getCause λ©”μ„œλ“œ 호좜 μ‹œμ— 전체 μ˜ˆμ™Έμ— λŒ€ν•œ λ©”μ‹œμ§€κ°€ λ‹΄κΈ΄ throwable을 λ°˜ν™˜ν•˜λŠ” 것이 더 쒋을 것 κ°™μŠ΅λ‹ˆλ‹€.

OperationException: msg1
    at net.spy.memcached.internal.CompositeExceptionTest.printStackTraceOfAllExceptions(CompositeExceptionTest.java:17)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    ...
OperationException: msg2
    at net.spy.memcached.internal.CompositeExceptionTest.printStackTraceOfAllExceptions(CompositeExceptionTest.java:18)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    ...
OperationException: msg3
    at net.spy.memcached.internal.CompositeExceptionTest.throwError2(CompositeExceptionTest.java:34)
    at net.spy.memcached.internal.CompositeExceptionTest.throwError1(CompositeExceptionTest.java:31)
    at net.spy.memcached.internal.CompositeExceptionTest.printStackTraceOfAllExceptions(CompositeExceptionTest.java:19)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    ...

@jhpark816

κΈ°μ‘΄μ—λŠ” 내뢀에 λ‹΄κΈ΄ Exceptionλ“€μ˜ μŠ€νƒνŠΈλ ˆμ΄μŠ€κ°€ 없이 CompositeException 자체의 μŠ€νƒνŠΈλ ˆμ΄μŠ€λ§Œ λ°˜ν™˜λ˜μ—ˆμŠ΅λ‹ˆλ‹€.

net.spy.memcached.internal.CompositeException: Multiple exceptions (3) reported: msg1, msg2, msg3
	at net.spy.memcached.internal.CompositeExceptionTest.printStackTraceOfAllExceptions(CompositeExceptionTest.java:21)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:728)
        ...

@oliviarla oliviarla self-assigned this Nov 21, 2024
Copy link
Collaborator

@uhm0311 uhm0311 left a comment

Choose a reason for hiding this comment

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

2μ°¨, μ§ˆλ¬Έμž…λ‹ˆλ‹€.

@oliviarla oliviarla force-pushed the composite branch 3 times, most recently from 0b102a0 to cce2682 Compare November 21, 2024 08:38
Copy link
Collaborator

@uhm0311 uhm0311 left a comment

Choose a reason for hiding this comment

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

3μ°¨ 리뷰 μ˜κ²¬μž…λ‹ˆλ‹€.

exceptions.add(new OperationException(OperationErrorType.SERVER, "msg1"));
exceptions.add(new OperationException(OperationErrorType.CLIENT, "msg2"));

logger.error("failed to get", new CompositeException(exceptions));
Copy link
Collaborator

Choose a reason for hiding this comment

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

이 λ‘œκ±°λŠ” μžλ°” ν΄λΌμ΄μ–ΈνŠΈ 내뢀에 κ΅¬ν˜„λœ 둜거λ₯Ό μ‚¬μš©ν•  κ²ƒμž…λ‹ˆλ‹€.
log4j μ˜μ‘΄μ„±μ€ 이미 ν¬ν•¨λ˜μ–΄ μžˆμœΌλ‹ˆ log4j의 λ‘œκ±°λ„ ν•œ 번 μ‚¬μš©ν•΄λ΄…μ‹œλ‹€.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

log4j μ‚¬μš©ν•˜λŠ” ν…ŒμŠ€νŠΈλ„ μΆ”κ°€ν–ˆμŠ΅λ‹ˆλ‹€.

Comment on lines 18 to 20
super(ExceptionMessageFactory.createCompositeMessage(exceptions));
if (exceptions.size() > 1) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

사이에 Empty Line μΆ”κ°€

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

empty line 같은 κ²½μš°μ—λŠ” μ •ν•΄μ ΈμžˆλŠ” 룰이 μžˆμ—ˆλ‚˜μš”?
가독성 μ’‹μ•„λ³΄μ΄κ²Œ 제 λ‚˜λ¦„λŒ€λ‘œ μˆ˜μ •ν•΄λ‘μ—ˆμŠ΅λ‹ˆλ‹€.

@jhpark816 jhpark816 merged commit 381b25a into naver:develop Nov 25, 2024
2 checks passed
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.

3 participants