BugFix - 41265 - Mobile Drag XY Fix#3946
Conversation
WalkthroughThe pull request introduces several enhancements across multiple files, focusing on improving error handling, logging mechanisms, and initialization of properties. Key changes include the addition of Changes
Possibly related PRs
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (1)
Ginger/GingerCoreNET/Telemetry/TelemetryQueueManager.cs (1)
Line range hint
1-203: Summary of changes and suggestion for further improvementsThe changes in this file focus on improving null safety in the
AddLogmethod of theTelemetryQueueManagerclass. These modifications effectively address potential null reference issues and align well with the PR objective of bug fixing.While the current changes are valuable, consider applying similar null safety improvements to other methods in the class, particularly
AddFeatureUsage. This would ensure consistent null handling throughout the telemetry logging functionality.Consider applying similar null safety improvements to the
AddFeatureUsagemethod:public void AddFeatureUsage(FeatureId featureId, TimeSpan? duration, TelemetryMetadata metadata) { - Solution? solution = WorkSpace.Instance.Solution; + Solution? solution = WorkSpace.Instance?.Solution; + string? userId = WorkSpace.Instance?.UserProfile?.UserName; TelemetryFeatureRecord featureRecord = new() { SolutionId = solution != null ? solution.Guid.ToString() : "", Account = solution != null && solution.Account != null ? solution.Account : "", AppVersion = ApplicationInfo.ApplicationBackendVersion, - UserId = WorkSpace.Instance.UserProfile.UserName, + UserId = userId, CreationTimestamp = DateTime.UtcNow, LastUpdateTimestamp = DateTime.UtcNow, FeatureId = featureId.ToString(), Duration = duration, Metadata = metadata.ToJSON(), }; _featureQueue.Enqueue(featureRecord); }This change would make the null safety handling consistent across both
AddLogandAddFeatureUsagemethods.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
- Ginger/GingerCoreCommon/ReporterLib/Reporter.cs (1 hunks)
- Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs (1 hunks)
- Ginger/GingerCoreNET/Telemetry/TelemetryQueueManager.cs (1 hunks)
🧰 Additional context used
🪛 GitHub Check: Codacy Static Code Analysis
Ginger/GingerCoreCommon/ReporterLib/Reporter.cs
[warning] 82-82: Ginger/GingerCoreCommon/ReporterLib/Reporter.cs#L82
Either remove or fill this block of code.
[notice] 82-82: Ginger/GingerCoreCommon/ReporterLib/Reporter.cs#L82
Handle the exception or explain in a comment why it can be ignored.
🔇 Additional comments (4)
Ginger/GingerCoreNET/Telemetry/TelemetryQueueManager.cs (2)
128-129: Improved null safety in WorkSpace and UserProfile accessThe changes in these lines enhance the null safety of the code by using null-conditional operators (
?.) when accessingWorkSpace.Instanceand its properties. This prevents potential null reference exceptions ifWorkSpace.InstanceorUserProfileis null.These modifications align well with the PR objective of bug fixing and improve the overall robustness of the telemetry logging functionality.
136-136: Consistent null safety improvement in UserId assignmentThis change ensures that the
UserIdin theTelemetryLogRecordis assigned the potentially null value fromuserId. This is consistent with the null safety improvements made earlier in the method.This modification further enhances the robustness of the telemetry logging by gracefully handling cases where the user profile information might not be available.
Ginger/GingerCoreCommon/ReporterLib/Reporter.cs (2)
Line range hint
138-138: LGTM: Proper initialization of Metadata property.The initialization of the
Metadataproperty as an empty array is a good practice. It ensures that the property is always in a defined state, preventing potential null reference exceptions and improving code reliability.🧰 Tools
🪛 GitHub Check: Codacy Static Code Analysis
[warning] 82-82: Ginger/GingerCoreCommon/ReporterLib/Reporter.cs#L82
Either remove or fill this block of code.
[notice] 82-82: Ginger/GingerCoreCommon/ReporterLib/Reporter.cs#L82
Handle the exception or explain in a comment why it can be ignored.
Line range hint
1-1: Verify relevance to PR objective.The changes in this file improve error handling in telemetry logging and property initialization. However, they don't seem directly related to the stated PR objective of fixing mobile drag functionality (bug 41265).
Could you please clarify how these changes contribute to the mobile drag XY fix mentioned in the PR title? If they're unrelated, consider separating these changes into a different PR for better traceability.
🧰 Tools
🪛 GitHub Check: Codacy Static Code Analysis
[warning] 82-82: Ginger/GingerCoreCommon/ReporterLib/Reporter.cs#L82
Either remove or fill this block of code.
[notice] 82-82: Ginger/GingerCoreCommon/ReporterLib/Reporter.cs#L82
Handle the exception or explain in a comment why it can be ignored.
| try | ||
| { | ||
| msg = $"{messageToLog}\n{exceptionToLog}"; | ||
| } | ||
| else | ||
| { | ||
| msg = messageToLog; | ||
| } | ||
| if (metadata == null) | ||
| { | ||
| TelemetryQueueManager.AddLog(logLevel, msg); | ||
| } | ||
| else | ||
| { | ||
| TelemetryQueueManager.AddLog(logLevel, msg, metadata); | ||
| string msg; | ||
| if (exceptionToLog != null) | ||
| { | ||
| msg = $"{messageToLog}\n{exceptionToLog}"; | ||
| } | ||
| else | ||
| { | ||
| msg = messageToLog; | ||
| } | ||
| if (metadata == null) | ||
| { | ||
| TelemetryQueueManager.AddLog(logLevel, msg); | ||
| } | ||
| else | ||
| { | ||
| TelemetryQueueManager.AddLog(logLevel, msg, metadata); | ||
| } | ||
| } | ||
| catch { } |
There was a problem hiding this comment.
Improve error handling in telemetry logging.
The addition of the try-catch block enhances the robustness of the ToLog method by preventing exceptions in telemetry logging from disrupting the application flow. This is a good improvement.
However, the empty catch block on line 82 is problematic:
An empty catch block silently swallows exceptions, making it difficult to diagnose issues in production. Consider logging the exception or handling it appropriately.
Here's a suggested improvement:
try
{
// ... existing code ...
}
-catch { }
+catch (Exception ex)
+{
+ // Log the exception without re-throwing to maintain the original behavior
+ System.Diagnostics.Debug.WriteLine($"Error in telemetry logging: {ex.Message}");
+}This change logs the exception message for debugging purposes without affecting the application's behavior.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| try | |
| { | |
| msg = $"{messageToLog}\n{exceptionToLog}"; | |
| } | |
| else | |
| { | |
| msg = messageToLog; | |
| } | |
| if (metadata == null) | |
| { | |
| TelemetryQueueManager.AddLog(logLevel, msg); | |
| } | |
| else | |
| { | |
| TelemetryQueueManager.AddLog(logLevel, msg, metadata); | |
| string msg; | |
| if (exceptionToLog != null) | |
| { | |
| msg = $"{messageToLog}\n{exceptionToLog}"; | |
| } | |
| else | |
| { | |
| msg = messageToLog; | |
| } | |
| if (metadata == null) | |
| { | |
| TelemetryQueueManager.AddLog(logLevel, msg); | |
| } | |
| else | |
| { | |
| TelemetryQueueManager.AddLog(logLevel, msg, metadata); | |
| } | |
| } | |
| catch { } | |
| try | |
| { | |
| string msg; | |
| if (exceptionToLog != null) | |
| { | |
| msg = $"{messageToLog}\n{exceptionToLog}"; | |
| } | |
| else | |
| { | |
| msg = messageToLog; | |
| } | |
| if (metadata == null) | |
| { | |
| TelemetryQueueManager.AddLog(logLevel, msg); | |
| } | |
| else | |
| { | |
| TelemetryQueueManager.AddLog(logLevel, msg, metadata); | |
| } | |
| } | |
| catch (Exception ex) | |
| { | |
| // Log the exception without re-throwing to maintain the original behavior | |
| System.Diagnostics.Debug.WriteLine($"Error in telemetry logging: {ex.Message}"); | |
| } |
🧰 Tools
🪛 GitHub Check: Codacy Static Code Analysis
[warning] 82-82: Ginger/GingerCoreCommon/ReporterLib/Reporter.cs#L82
Either remove or fill this block of code.
[notice] 82-82: Ginger/GingerCoreCommon/ReporterLib/Reporter.cs#L82
Handle the exception or explain in a comment why it can be ignored.
| TimeSpan.FromMilliseconds(Convert.ToDouble(act.PressDuration.ValueForDriver)), | ||
| TimeSpan.FromMilliseconds(Convert.ToDouble(act.DragDuration.ValueForDriver))); |
There was a problem hiding this comment.
Update method call to match parameter type changes
The DragAndDropByXY method's parameters pressDuration and dragDuration have been changed from TimeSpan to double. Currently, the method call is passing TimeSpan objects, which will result in a type mismatch. Please update the method call to pass double values representing the durations in milliseconds.
Apply this diff to fix the method call:
- TimeSpan.FromMilliseconds(Convert.ToDouble(act.PressDuration.ValueForDriver)),
- TimeSpan.FromMilliseconds(Convert.ToDouble(act.DragDuration.ValueForDriver)));
+ Convert.ToDouble(act.PressDuration.ValueForDriver),
+ Convert.ToDouble(act.DragDuration.ValueForDriver));📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| TimeSpan.FromMilliseconds(Convert.ToDouble(act.PressDuration.ValueForDriver)), | |
| TimeSpan.FromMilliseconds(Convert.ToDouble(act.DragDuration.ValueForDriver))); | |
| Convert.ToDouble(act.PressDuration.ValueForDriver), | |
| Convert.ToDouble(act.DragDuration.ValueForDriver)); |
Thank you for your contribution.
Before submitting this PR, please make sure:
Summary by CodeRabbit
New Features
Improvements
Bug Fixes