Refactor EdgeHitProcessor.processHit to clean up error handling#19
Refactor EdgeHitProcessor.processHit to clean up error handling#19kevinlind merged 14 commits intoadobe:dev-v2.0.0from
Conversation
Codecov Report
@@ Coverage Diff @@
## dev-v2.0.0 #19 +/- ##
================================================
+ Coverage 83.17% 83.40% +0.23%
- Complexity 380 386 +6
================================================
Files 29 29
Lines 1545 1566 +21
Branches 219 221 +2
================================================
+ Hits 1285 1306 +21
Misses 161 161
Partials 99 99
Flags with carried forward coverage won't be shown. Click here to find out more.
|
code/edge/src/main/java/com/adobe/marketing/mobile/EdgeHitProcessor.java
Show resolved
Hide resolved
emdobrin
left a comment
There was a problem hiding this comment.
looks great, and thanks for splitting that method up 👍
code/edge/src/main/java/com/adobe/marketing/mobile/EdgeHitProcessor.java
Outdated
Show resolved
Hide resolved
code/edge/src/test/java/com/adobe/marketing/mobile/EdgeNetworkServiceTest.java
Outdated
Show resolved
Hide resolved
code/edge/src/main/java/com/adobe/marketing/mobile/CompletionCallbacksManager.java
Outdated
Show resolved
Hide resolved
code/edge/src/androidTest/java/com/adobe/marketing/mobile/CompletionHandlerFunctionalTests.java
Show resolved
Hide resolved
| // Tests that when a good hit is processed that a network request is made and the request returns 200 | ||
|
|
||
| // setup | ||
| Map<String, Object> config = new HashMap<>(); |
There was a problem hiding this comment.
Should we add test cases with null config map?
| final String responseStr = | ||
| "<RS>{\"some\":\"thing1\\n\"}<LF>" + | ||
| "<RS>{\"some\":\"thing2\\n\"}<LF>" + | ||
| "<RS>{\"some\":\"thing3\\n\"}<LF>."; // note the trailing '.' character |
There was a problem hiding this comment.
Should we add comment saying "." is dropped with the exception?
| while (scanner.hasNext()) { | ||
| final String jsonResult = scanner.next(); | ||
| responseCallback.onResponse(jsonResult.substring(trimLength)); | ||
| try { |
There was a problem hiding this comment.
Is it possible to avoid the exception all together by adding a check like this?
if (jsonResult.length() > trimlength) {
responseCallback.onResponse(jsonResult.substring(trimLength));
}
There was a problem hiding this comment.
I updated this to check the length instead of adding the try/catch block. If the jsonResult length is less than the record separator length, then I log a debug stating the response is ignored.
| StringWriter stringWriter = new StringWriter(); | ||
| PrintWriter printWriter = new PrintWriter(stringWriter); | ||
| ex.printStackTrace(printWriter); | ||
|
|
||
| Log.warning( | ||
| LOG_TAG, | ||
| LOG_SOURCE, | ||
| "Exception thrown when invoking EdgeCallback.onComplete() for request event id %s: %s", | ||
| requestEventId, | ||
| stringWriter.toString() |
There was a problem hiding this comment.
Reading more about this it looks like it is recommended to use the platform level logging support for exceptions instead of printStackTrace.
@praveek any chance would could support for logging throwable in the Logging service as the platform provides?
https://developer.android.com/reference/android/util/Log#w(java.lang.String,%20java.lang.Throwable)
Alternatively we can look into using https://developer.android.com/reference/android/util/Log#getStackTraceString(java.lang.Throwable)
There was a problem hiding this comment.
@emdobrin We can explore about adding these additional log methods after the 2.0 release. For now, I would prefer getStackTraceString to get the string representation of stack trace.
nit: Can we reword the log to Exception thrown when invoking completion callback for request event id
EdgeCallback.onComplete() is not very intuitive when a customer passes lambda.
There was a problem hiding this comment.
@kevinlind can you make this update and also create a feature request for the logging service in aepsdk-core-android?
There was a problem hiding this comment.
I've updated the log message as suggested. I also created an issue in Android Core to add LoggingService APIs to support throwable objects, adobe/aepsdk-core-android#349
…n processing network response
… configuration is empty
| PrintWriter printWriter = new PrintWriter(stringWriter); | ||
| ex.printStackTrace(printWriter); | ||
|
|
||
| Log.warning( |
There was a problem hiding this comment.
Log warning will look like the following, where an NPE is thrown from "throwUp" which is called from EdgeCallback.onComplete:
2023-01-20 10:16:15.788 16047-16192/com.adobe.marketing.edgetestapp W/AdobeExperienceSDK: Edge/CompletionCallbacksManager - Exception thrown when invoking EdgeCallback for request event id 00c61fbb-4c43-476e-9fd0-acc20a958b93: java.lang.NullPointerException: Catch me!
at com.adobe.marketing.tester.MainActivity.throwUp(MainActivity.java:239)
at com.adobe.marketing.tester.MainActivity.lambda$onSubmitSingleEvent$1$com-adobe-marketing-tester-MainActivity(MainActivity.java:232)
at com.adobe.marketing.tester.MainActivity$$ExternalSyntheticLambda4.onComplete(Unknown Source:6)
at com.adobe.marketing.mobile.CompletionCallbacksManager.unregisterCallback(CompletionCallbacksManager.java:97)
at com.adobe.marketing.mobile.EdgeHitProcessor$1.onComplete(EdgeHitProcessor.java:142)
at com.adobe.marketing.mobile.EdgeNetworkService.doRequest(EdgeNetworkService.java:230)
at com.adobe.marketing.mobile.EdgeHitProcessor.sendNetworkRequest(EdgeHitProcessor.java:175)
at com.adobe.marketing.mobile.EdgeHitProcessor.processExperienceEventHit(EdgeHitProcessor.java:267)
at com.adobe.marketing.mobile.EdgeHitProcessor.processHit(EdgeHitProcessor.java:97)
at com.adobe.marketing.mobile.services.PersistentHitQueue.lambda$processNextHit$2$com-adobe-marketing-mobile-services-PersistentHitQueue(PersistentHitQueue.java:118)
at com.adobe.marketing.mobile.services.PersistentHitQueue$$ExternalSyntheticLambda0.run(Unknown Source:2)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:463)
at java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:307)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
at java.lang.Thread.run(Thread.java:1012)
| while (scanner.hasNext()) { | ||
| final String jsonResult = scanner.next(); | ||
| responseCallback.onResponse(jsonResult.substring(trimLength)); | ||
| try { |
There was a problem hiding this comment.
I updated this to check the length instead of adding the try/catch block. If the jsonResult length is less than the record separator length, then I log a debug stating the response is ignored.
| StringWriter stringWriter = new StringWriter(); | ||
| PrintWriter printWriter = new PrintWriter(stringWriter); | ||
| ex.printStackTrace(printWriter); | ||
|
|
||
| Log.warning( | ||
| LOG_TAG, | ||
| LOG_SOURCE, | ||
| "Exception thrown when invoking EdgeCallback.onComplete() for request event id %s: %s", | ||
| requestEventId, | ||
| stringWriter.toString() |
There was a problem hiding this comment.
I've updated the log message as suggested. I also created an issue in Android Core to add LoggingService APIs to support throwable objects, adobe/aepsdk-core-android#349
Description
Related Issue
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: