fix: preserve exception cause in error handling paths - #453
Open
chenjunwenhao wants to merge 1 commit into
Open
Conversation
Several catch blocks were silently discarding the original exception when reporting errors through ErrorReporter, making debugging extremely difficult. This fix ensures the caught exception is passed as catchObj so it is available as the cause of the resulting QLRuntimeException. Changes: - NewInstanceInstruction: pass Exception e to errorReporter.report() - NewFilledInstanceInstruction: pass Exception e to errorReporter.report() - ForEachInstruction: pass UserDefineException and Throwable to errorReporter - ReflectLoader.unwrapMethodInvokeEx: pass IllegalArgumentException as catchObj - ThrowUtils.reportUserDefinedException: pass UserDefineException as catchObj - Express4Runner.parseToDefinitionWithCache: handle null e.getCause() Also fixes MockErrorReporter to properly propagate catchObj for testing.
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Several catch blocks throughout the codebase were silently discarding the original exception when reporting errors through
ErrorReporter. This made debugging extremely difficult because the root cause was lost from the exception chain.Root Cause
The
ErrorReporterinterface has tworeportoverloads:report(Object catchObj, String errorCode, String reason)— preserves the exception ascatchObj, which becomes thecauseof the resultingQLRuntimeExceptionreport(String errorCode, String reason)— passesnullascatchObj, losing the original exceptionMultiple catch blocks were using the second overload, causing the caught exception to be completely discarded.
Fixes
NewInstanceInstruction.javacatch (Exception e)didn't passetoerrorReporter.report()NewFilledInstanceInstruction.javacatch (Exception e)didn't passetoerrorReporter.report()ForEachInstruction.javacatch (UserDefineException e)andcatch (Throwable t)didn't pass exceptionsReflectLoader.unwrapMethodInvokeEx()IllegalArgumentExceptionbranch usedreportFormat(no cause) instead ofreportFormatWithCatch— affects 5 call sitesThrowUtils.reportUserDefinedException()UserDefineExceptionnot passed ascatchObj— affects 6 call sitesExpress4Runner.parseToDefinitionWithCache()e.getCause()can be null (e.g.,InterruptedException), causingnew RuntimeException(null)Tests
exceptionCausePreservedTestinNewInstanceInstructionTest— verifies thatInstantiationException(from instantiating an interface) is preserved as the causeparseToDefinitionWithCacheInvalidScriptTestinExpress4RunnerTest— verifies error propagation for invalid scriptsmethodInvokeWrongArgTypeCausePreservedTestinExpress4RunnerTest— verifiesIllegalArgumentExceptionis preserved when calling a method with wrong argument typesMockErrorReporterto propagatecatchObj(was hardcoded tonull), enabling proper test verificationTest plan
getCause()returns the original exceptionMockErrorReporterfix is backward-compatible sincecatchObjis only used forinitCausewhen it's aThrowable)