Skip to content

BugFix - 41265 - Mobile Drag XY Fix#3946

Merged
Maheshkale447 merged 1 commit into
Releases/Official-Releasefrom
BugFix/MobileDragXYFix
Oct 1, 2024
Merged

BugFix - 41265 - Mobile Drag XY Fix#3946
Maheshkale447 merged 1 commit into
Releases/Official-Releasefrom
BugFix/MobileDragXYFix

Conversation

@IamHarsimranjeet

@IamHarsimranjeet IamHarsimranjeet commented Oct 1, 2024

Copy link
Copy Markdown
Contributor

Thank you for your contribution.
Before submitting this PR, please make sure:

  • PR description and commit message should describe the changes done in this PR
  • Verify the PR is pointing to correct branch i.e. Release or Beta branch if the code fix is for specific release , else point it to master
  • Latest Code from master or specific release branch is merged to your branch
  • No unwanted\commented\junk code is included
  • No new warning upon build solution
  • Code Summary\Comments are added to my code which explains what my code is doing
  • Existing unit test cases are passed
  • New Unit tests are added for your development
  • Sanity Tests are successfully executed for New and Existing Functionality
  • Verify that changes are compatible with all relevant browsers and platforms.
  • After creating pull request there should not be any conflicts
  • Resolve all Codacy comments
  • Builds and checks are passed before PR is sent for review
  • Resolve code review comments
  • Update the Help Library document to match any feature changes

Summary by CodeRabbit

  • New Features

    • Enhanced error handling for telemetry logging to prevent application crashes.
    • Added new properties for device metrics in mobile testing.
    • Introduced a method for streamlined retrieval of device performance data.
  • Improvements

    • Improved handling of mobile device actions with more precise control over drag and swipe actions.
    • Enhanced null safety in telemetry logging to handle missing workspace or user profile data.
  • Bug Fixes

    • Refined error handling mechanisms for better logging and meaningful error messages.

@coderabbitai

coderabbitai Bot commented Oct 1, 2024

Copy link
Copy Markdown
Contributor

Walkthrough

The 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 try-catch blocks in telemetry logging, updates to method parameters for better precision in mobile actions, and enhancements for null safety in telemetry data handling.

Changes

File Path Change Summary
Ginger/GingerCoreCommon/ReporterLib/Reporter.cs Introduced error handling in ToLog method with a try-catch block and initialized Metadata property in MockFeatureTracker as an empty array.
Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs Updated method signatures for PerformDrag and SwipeScreen to use double for timing parameters, refined error handling, and added GetDeviceMetricsString method.
Ginger/GingerCoreNET/Telemetry/TelemetryQueueManager.cs Enhanced null safety in AddLog and AddFeatureUsage methods, ensuring safe retrieval of Solution and UserId from WorkSpace.Instance.

Possibly related PRs

Suggested reviewers

  • Maheshkale447

🐇 In the code we hop and play,
With logs and metrics on display.
Error handling, oh so bright,
Keeps our app running just right!
From drag to swipe, we’ve made it clear,
A smoother path, let’s give a cheer!
🌟


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 improvements

The changes in this file focus on improving null safety in the AddLog method of the TelemetryQueueManager class. 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 AddFeatureUsage method:

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 AddLog and AddFeatureUsage methods.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 942a57f and eefe6f0.

📒 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 access

The changes in these lines enhance the null safety of the code by using null-conditional operators (?.) when accessing WorkSpace.Instance and its properties. This prevents potential null reference exceptions if WorkSpace.Instance or UserProfile is 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 assignment

This change ensures that the UserId in the TelemetryLogRecord is assigned the potentially null value from userId. 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 Metadata property 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.

Comment on lines +62 to +82
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 { }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

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.

Suggested change
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.

Comment on lines +1006 to +1007
TimeSpan.FromMilliseconds(Convert.ToDouble(act.PressDuration.ValueForDriver)),
TimeSpan.FromMilliseconds(Convert.ToDouble(act.DragDuration.ValueForDriver)));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

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.

Suggested change
TimeSpan.FromMilliseconds(Convert.ToDouble(act.PressDuration.ValueForDriver)),
TimeSpan.FromMilliseconds(Convert.ToDouble(act.DragDuration.ValueForDriver)));
Convert.ToDouble(act.PressDuration.ValueForDriver),
Convert.ToDouble(act.DragDuration.ValueForDriver));

@Maheshkale447
Maheshkale447 merged commit 6443e20 into Releases/Official-Release Oct 1, 2024
@Maheshkale447
Maheshkale447 deleted the BugFix/MobileDragXYFix branch October 1, 2024 12:06
@coderabbitai coderabbitai Bot mentioned this pull request Nov 24, 2024
15 tasks
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.

2 participants