Skip to content

Handled Exception for run-set execution#4279

Merged
prashelke merged 1 commit into
masterfrom
BugFix/CategoryRelatedChanges
Aug 21, 2025
Merged

Handled Exception for run-set execution#4279
prashelke merged 1 commit into
masterfrom
BugFix/CategoryRelatedChanges

Conversation

@prashelke

@prashelke prashelke commented Aug 20, 2025

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

  • Bug Fixes
    • Improved stability when solution categories are absent by adding null-safety, preventing unexpected errors in category lookups.
    • Enhanced robustness of runset start logging: category fields now safely default to empty when not defined, avoiding failures in centralized execution reports.
    • Maintains existing behavior when categories are present; no changes to user-facing workflows or outputs beyond preventing crashes and errors in edge cases.

@coderabbitai

coderabbitai Bot commented Aug 20, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Introduces null-safety around solution category access in General.cs and adds guarded checks before mapping category fields in AccountReportEntitiesDataMapping.cs to avoid null references. No public API changes.

Changes

Cohort / File(s) Summary of Changes
Null-safety in solution category retrieval
Ginger/GingerCoreNET/GeneralLib/General.cs
Wrapped GetSolutionCategoryValue logic with a null check on WorkSpace.Instance.Solution.SolutionCategories; returns null when categories are absent; no signature changes.
Guarded runset category mapping
Ginger/GingerCoreNET/Run/RunListenerLib/CenteralizedExecutionLogger/AccountReportEntitiesDataMapping.cs
In MapRunsetStartData, added presence checks for each category before fetching via GetSolutionCategoryValue; assigns empty string when not present; no public API changes.

Sequence Diagram(s)

sequenceDiagram
  actor Caller
  participant General as General.GetSolutionCategoryValue
  Caller->>General: GetSolutionCategoryValue(categoryName, ...)
  alt SolutionCategories is null
    General-->>Caller: null
  else Category present and value found
    General-->>Caller: value
  else Category/value not found
    General-->>Caller: null
  end
Loading
sequenceDiagram
  participant Runner as MapRunsetStartData
  participant Config as runSetConfig
  participant General as GetSolutionCategoryValue
  Runner->>Config: Check CategoriesDefinitions for "Product"/"Release"/...
  alt Category exists
    Runner->>General: Fetch solution category value
    General-->>Runner: value (or null)
    note over Runner: Assign value or empty if null
  else Category missing
    note over Runner: Assign empty string
  end
  Runner-->>Runner: Continue mapping other fields
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • ravirk91
  • Maheshkale447

Poem

A hop, a stop—no nulls to fear,
I nibbled guards both far and near.
Categories checked, safe paths we tread,
Empty strings where danger spread.
With twitching nose and tidy logs,
I tame exceptions—clever hogs! 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between c505646 and 2837107.

📒 Files selected for processing (2)
  • Ginger/GingerCoreNET/GeneralLib/General.cs (1 hunks)
  • Ginger/GingerCoreNET/Run/RunListenerLib/CenteralizedExecutionLogger/AccountReportEntitiesDataMapping.cs (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: GokulBothe99
PR: Ginger-Automation/Ginger#4049
File: Ginger/GingerCoreNET/Clients/GraphQLClients/ExecutionReportGraphQLClient.cs:140-147
Timestamp: 2025-01-09T12:58:16.975Z
Learning: In the Ginger project, exceptions should be handled in a dedicated exception handling class rather than inline, following the Single Responsibility Principle and promoting code reusability.
📚 Learning: 2025-07-31T06:50:34.654Z
Learnt from: jainamehta7
PR: Ginger-Automation/Ginger#4273
File: Ginger/GingerCoreCommon/Repository/BusinessFlowLib/BusinessFlow.cs:0-0
Timestamp: 2025-07-31T06:50:34.654Z
Learning: In the Ginger codebase, category management for BusinessFlow and Activity classes is handled through a centralized `General.EnsureAllCategories()` method located in `Ginger/GingerCoreCommon/GeneralLib/General.cs`. This method takes an `ObservableList<SolutionCategoryDefinition>` parameter and ensures it contains all categories defined in the `eSolutionCategories` enum. Classes like BusinessFlow and Activity call this method in their `AddCategories()` methods and `PostDeserialization()` methods to maintain consistent category definitions across the solution.

Applied to files:

  • Ginger/GingerCoreNET/GeneralLib/General.cs
📚 Learning: 2025-04-01T06:48:16.412Z
Learnt from: prashelke
PR: Ginger-Automation/Ginger#4150
File: Ginger/GingerCoreNET/Application Models/Delta/PomDelta/MultiPomRunSetMapping.cs:28-28
Timestamp: 2025-04-01T06:48:16.412Z
Learning: The property in MultiPomRunSetMapping class was renamed from 'runSetConfig' to 'RunSetConfig' to follow C# PascalCase naming conventions for public properties.

Applied to files:

  • Ginger/GingerCoreNET/Run/RunListenerLib/CenteralizedExecutionLogger/AccountReportEntitiesDataMapping.cs
🧬 Code Graph Analysis (2)
Ginger/GingerCoreNET/GeneralLib/General.cs (2)
Ginger/GingerCoreNET/WorkSpaceLib/WorkSpace.cs (1)
  • WorkSpace (61-1006)
Ginger/GingerCoreCommon/WorkSpaceLib/Solution.cs (8)
  • Solution (43-654)
  • Solution (54-57)
  • SolutionCategory (563-569)
  • SolutionCategory (571-577)
  • SolutionCategory (579-585)
  • SolutionCategory (587-599)
  • SolutionCategory (601-609)
  • SolutionCategory (611-620)
Ginger/GingerCoreNET/Run/RunListenerLib/CenteralizedExecutionLogger/AccountReportEntitiesDataMapping.cs (1)
Ginger/GingerCoreNET/GeneralLib/General.cs (2)
  • General (58-1370)
  • GetSolutionCategoryValue (491-506)
🔇 Additional comments (2)
Ginger/GingerCoreNET/GeneralLib/General.cs (1)

493-505: Strengthen null checks and simplify GetSolutionCategoryValue

After scanning all ten call sites of GetSolutionCategoryValue, none assume it throws on missing context—so tightening the guards here is safe and prevents rare NREs.

• File: Ginger/GingerCoreNET/GeneralLib/General.cs (lines 493–505)
Replace the current block with:

-            if (WorkSpace.Instance.Solution.SolutionCategories != null)
-            {
-                SolutionCategory cat = WorkSpace.Instance.Solution.SolutionCategories.FirstOrDefault(x => x.Category == solutionCategoryDefinition.Category);
-                if (cat != null)
-                {
-                    SolutionCategoryValue catValue = cat.CategoryOptionalValues.FirstOrDefault(x => x.Guid == solutionCategoryDefinition.SelectedValueID);
-                    if (catValue != null)
-                    {
-                        return catValue.Value;
-                    }
-                }
-            }
-            return null;
+            var categories = WorkSpace.Instance?.Solution?.SolutionCategories;
+            if (categories?.Any() == true)
+            {
+                var cat = categories.FirstOrDefault(x => x.Category == solutionCategoryDefinition.Category);
+                var catValue = cat?.CategoryOptionalValues?.FirstOrDefault(x => x.Guid == solutionCategoryDefinition.SelectedValueID);
+                return catValue?.Value;
+            }
+            return null;

Optional follow-up: if you’d like callers to always get a non-null string, consider using GetSolutionCategoryValue(...) ?? string.Empty at the call sites in
AccountReportEntitiesDataMapping.cs (lines 500–508).

Ginger/GingerCoreNET/Run/RunListenerLib/CenteralizedExecutionLogger/AccountReportEntitiesDataMapping.cs (1)

500-508: Refactor repeated category lookups to a single helper

Centralize null-guarding, remove double enumerations, and normalize missing values to an empty string.

• Location
– Ginger/GingerCoreNET/Run/RunListenerLib/CenteralizedExecutionLogger/AccountReportEntitiesDataMapping.cs, lines 500–508

• Change summary

  1. Add a helper inside AccountReportEntitiesDataMapping:

    private static string GetCategoryValueOrEmpty(RunSetConfig runSetConfig, SolutionCategory.eSolutionCategories category)
    {
        var def = runSetConfig.CategoriesDefinitions?.FirstOrDefault(x => x.Category == category);
        var value = def != null
            ? GingerCoreNET.GeneralLib.General.GetSolutionCategoryValue(def)
            : null;
        return value ?? string.Empty;
    }
  2. Replace the repeated Any + FirstOrDefault blocks with calls to this helper:

    -    Product = runSetConfig.CategoriesDefinitions.Any(x => x.Category == SolutionCategory.eSolutionCategories.Product)
    -        ? GingerCoreNET.GeneralLib.General.GetSolutionCategoryValue(runSetConfig.CategoriesDefinitions.FirstOrDefault(x => x.Category == SolutionCategory.eSolutionCategories.Product))
    -        : string.Empty,
    +    Product = GetCategoryValueOrEmpty(runSetConfig, SolutionCategory.eSolutionCategories.Product),
    … (repeat for Release, Iteration, TestType, UserCategory1–3, BusinessProcessTag, SubBusinessProcessTag)

• Verification needed
Please confirm that an empty string is the correct “no value” wire-format for these report fields. If consumers expect null instead, adjust the last line of the helper to return value;.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch BugFix/CategoryRelatedChanges

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@prashelke
prashelke merged commit bae914f into master Aug 21, 2025
14 of 17 checks passed
@prashelke
prashelke deleted the BugFix/CategoryRelatedChanges branch August 21, 2025 04:48
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.

1 participant