Skip to content

Conversation

@cammiida
Copy link
Contributor

Description

Verification

  • Related issues are connected (if applicable)
  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)

@cammiida cammiida requested a review from adamhaeger November 26, 2025 07:59
@github-actions github-actions bot added skip-releasenotes Issues that do not make sense to list in our release notes skip-second-approval Pull requests that only need one approval from a reviewer. labels Nov 26, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 26, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch review/backend-data-loading

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@cammiida cammiida changed the title Review/backend data loading refactor: review backend data loading Nov 26, 2025
@cammiida cammiida force-pushed the review/backend-data-loading branch from a213ac8 to 5678a5c Compare November 26, 2025 08:26
Comment on lines +400 to +404
catch
{
// TODO: Log error
return null;
}

Check notice

Code scanning / CodeQL

Generic catch clause Note

Generic catch clause.

Copilot Autofix

AI 3 days ago

To fix the problem, the generic catch clause in the TryDeserialize<T> method should be replaced by specific exception handlers. For JSON deserialization, the correct exception is JsonException. Sometimes, deserialization might throw ArgumentNullException or ArgumentException (if the JSON is malformed or parameters are incorrect). We should catch those and return null, consistent with the intended behavior. Any other exceptions (which may signal internal problems, bugs, or environmental failures) should be rethrown or logged, not suppressed.

Changes need to be made only in the body of the TryDeserialize<T> method in the file src/App/backend/src/Altinn.App.Core/Features/Bootstrap/InitialDataService.cs, replacing the generic catch with targeted exception handling. No new imports are needed because JsonException is already available from System.Text.Json.

Suggested changeset 1
src/App/backend/src/Altinn.App.Core/Features/Bootstrap/InitialDataService.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/App/backend/src/Altinn.App.Core/Features/Bootstrap/InitialDataService.cs b/src/App/backend/src/Altinn.App.Core/Features/Bootstrap/InitialDataService.cs
--- a/src/App/backend/src/Altinn.App.Core/Features/Bootstrap/InitialDataService.cs
+++ b/src/App/backend/src/Altinn.App.Core/Features/Bootstrap/InitialDataService.cs
@@ -397,11 +397,21 @@
         {
             return JsonSerializer.Deserialize<T>(json, _jsonSerializerOptions);
         }
-        catch
+        catch (JsonException)
         {
             // TODO: Log error
             return null;
         }
+        catch (ArgumentException)
+        {
+            // TODO: Log error
+            return null;
+        }
+        catch (Exception)
+        {
+            // TODO: Log unexpected error
+            throw;
+        }
     }
 
     private async Task<bool> CanPartyInstantiate(int? partyId)
EOF
@@ -397,11 +397,21 @@
{
return JsonSerializer.Deserialize<T>(json, _jsonSerializerOptions);
}
catch
catch (JsonException)
{
// TODO: Log error
return null;
}
catch (ArgumentException)
{
// TODO: Log error
return null;
}
catch (Exception)
{
// TODO: Log unexpected error
throw;
}
}

private async Task<bool> CanPartyInstantiate(int? partyId)
Copilot is powered by AI and may make mistakes. Always verify output.
private Task GetMockParty(int partyId, InitialDataResponse response)
private Party? GetMockParty(int? partyId)
{
if (partyId.HasValue == false)

Check notice

Code scanning / CodeQL

Unnecessarily complex Boolean expression Note

The expression 'A == false' can be simplified to '!A'.

Copilot Autofix

AI 3 days ago

To fix the unnecessarily complex boolean expression, simply change partyId.HasValue == false to !partyId.HasValue. This is a direct, well-understood way to check that the nullable int does not have a value, is more concise, and improves readability. The change should be made at line 473 in src/App/backend/src/Altinn.App.Core/Features/Bootstrap/InitialDataService.cs. No additional imports, definitions, or special handling is needed, as this expression is well-supported in C# and does not modify any program logic or behavior outside the specific negation.

Suggested changeset 1
src/App/backend/src/Altinn.App.Core/Features/Bootstrap/InitialDataService.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/App/backend/src/Altinn.App.Core/Features/Bootstrap/InitialDataService.cs b/src/App/backend/src/Altinn.App.Core/Features/Bootstrap/InitialDataService.cs
--- a/src/App/backend/src/Altinn.App.Core/Features/Bootstrap/InitialDataService.cs
+++ b/src/App/backend/src/Altinn.App.Core/Features/Bootstrap/InitialDataService.cs
@@ -470,7 +470,7 @@
 
     private Party? GetMockParty(int? partyId)
     {
-        if (partyId.HasValue == false)
+        if (!partyId.HasValue)
         {
             return null;
         }
EOF
@@ -470,7 +470,7 @@

private Party? GetMockParty(int? partyId)
{
if (partyId.HasValue == false)
if (!partyId.HasValue)
{
return null;
}
Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/chore skip-releasenotes Issues that do not make sense to list in our release notes skip-second-approval Pull requests that only need one approval from a reviewer.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants