Skip to content

Conversation

@bjorntore
Copy link
Contributor

Description

Related Issue(s)

  • #{issue number}

Verification

  • 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)
  • All tests run green

Documentation

  • User documentation is updated with a separate linked PR in altinn-studio-docs. (if applicable)

…ult enum and use result classes instead, for expandability.
…elds from result class and instead return generic failed ProcessChangeResult.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 10, 2025

Important

Review skipped

Draft detected.

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 feat/subform-service-task

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.

@bjorntore bjorntore added backport-ignore This PR is a new feature and should not be cherry-picked onto release branches feature Label Pull requests with new features. Used when generation releasenotes labels Oct 10, 2025
@bjorntore
Copy link
Contributor Author

/publish

@github-actions
Copy link

github-actions bot commented Oct 10, 2025

PR release:

⚙️ Building...
✅ Done!

@bjorntore
Copy link
Contributor Author

/publish

@github-actions
Copy link

github-actions bot commented Oct 10, 2025

@bjorntore
Copy link
Contributor Author

/publish

@github-actions
Copy link

github-actions bot commented Oct 10, 2025

PR release:

⚙️ Building...
✅ Done!

Base automatically changed from feat/pdf-service-task to main October 30, 2025 10:34
# Conflicts:
#	src/Altinn.App.Core/Internal/Pdf/IPdfService.cs
#	src/Altinn.App.Core/Internal/Pdf/PdfService.cs
#	test/Altinn.App.Core.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt
Comment on lines +137 to +145
catch (Exception ex)
{
logger.LogWarning(
ex,
"Failed to delete existing subform PDF {DataElementId} from instance {InstanceId}",
pdf.Id,
instance.Id
);
}

Check notice

Code scanning / CodeQL

Generic catch clause Note

Generic catch clause.

Copilot Autofix

AI 8 days ago

To fix the problem, the generic catch clause should be replaced by a catch block that either only catches known, recoverable exceptions, or—if catching Exception is desired for code resilience—rethrows exceptions that should never be swallowed (like OperationCanceledException, ThreadAbortException, and possibly OutOfMemoryException). In most codebases, at minimum, OperationCanceledException should always be rethrown, as handling cancellation tokens is part of reliable async code.

To implement this:

  • Replace the catch (Exception ex) block starting at line 134 with a catch that rethrows OperationCanceledException.
  • The code will check the exception type and rethrow if it is an OperationCanceledException. All other exceptions are logged as before.
  • No new using/import is required because it is already in a context where System is available.
Suggested changeset 1
src/Altinn.App.Core/Internal/Process/ProcessTasks/ServiceTasks/SubformPdfServiceTask.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/Altinn.App.Core/Internal/Process/ProcessTasks/ServiceTasks/SubformPdfServiceTask.cs b/src/Altinn.App.Core/Internal/Process/ProcessTasks/ServiceTasks/SubformPdfServiceTask.cs
--- a/src/Altinn.App.Core/Internal/Process/ProcessTasks/ServiceTasks/SubformPdfServiceTask.cs
+++ b/src/Altinn.App.Core/Internal/Process/ProcessTasks/ServiceTasks/SubformPdfServiceTask.cs
@@ -133,6 +133,10 @@
                     }
                     catch (Exception ex)
                     {
+                        if (ex is OperationCanceledException)
+                        {
+                            throw;
+                        }
                         logger.LogWarning(
                             ex,
                             "Failed to delete existing subform PDF {DataElementId} from instance {InstanceId}",
EOF
@@ -133,6 +133,10 @@
}
catch (Exception ex)
{
if (ex is OperationCanceledException)
{
throw;
}
logger.LogWarning(
ex,
"Failed to delete existing subform PDF {DataElementId} from instance {InstanceId}",
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +149 to +156
catch (Exception ex)
{
logger.LogWarning(
ex,
"Error during subform PDF cleanup in instance {InstanceId}",
context.InstanceDataMutator.Instance.Id
);
}

Check notice

Code scanning / CodeQL

Generic catch clause Note

Generic catch clause.

Copilot Autofix

AI 8 days ago

To address the generic catch clause, replace catch (Exception ex) with one or more specific catch clauses for the anticipated exceptions, such as OperationCanceledException for cancellation, and possibly more specific ones based on what dataClient.DeleteData and related code can throw (e.g., network exceptions, data-related exceptions, etc.). If there are cases where you still want to catch unexpected exceptions and log them, consider either rethrowing them after logging, or using a generic catch only with justification. For now, catch OperationCanceledException and log as cancellation, and optionally let other exceptions propagate or log them separately for distinction. All changes are in CleanupExistingSubformPdfs, between lines 146–153.


Suggested changeset 1
src/Altinn.App.Core/Internal/Process/ProcessTasks/ServiceTasks/SubformPdfServiceTask.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/Altinn.App.Core/Internal/Process/ProcessTasks/ServiceTasks/SubformPdfServiceTask.cs b/src/Altinn.App.Core/Internal/Process/ProcessTasks/ServiceTasks/SubformPdfServiceTask.cs
--- a/src/Altinn.App.Core/Internal/Process/ProcessTasks/ServiceTasks/SubformPdfServiceTask.cs
+++ b/src/Altinn.App.Core/Internal/Process/ProcessTasks/ServiceTasks/SubformPdfServiceTask.cs
@@ -143,13 +143,23 @@
                 }
             }
         }
+        catch (OperationCanceledException ocex)
+        {
+            logger.LogInformation(
+                ocex,
+                "PDF cleanup for component {SubformComponentId} in instance {InstanceId} was cancelled.",
+                subformComponentId,
+                context.InstanceDataMutator.Instance.Id
+            );
+        }
         catch (Exception ex)
         {
             logger.LogWarning(
                 ex,
-                "Error during subform PDF cleanup in instance {InstanceId}",
+                "Unhandled error during subform PDF cleanup in instance {InstanceId}",
                 context.InstanceDataMutator.Instance.Id
             );
+            throw;
         }
     }
 
EOF
@@ -143,13 +143,23 @@
}
}
}
catch (OperationCanceledException ocex)
{
logger.LogInformation(
ocex,
"PDF cleanup for component {SubformComponentId} in instance {InstanceId} was cancelled.",
subformComponentId,
context.InstanceDataMutator.Instance.Id
);
}
catch (Exception ex)
{
logger.LogWarning(
ex,
"Error during subform PDF cleanup in instance {InstanceId}",
"Unhandled error during subform PDF cleanup in instance {InstanceId}",
context.InstanceDataMutator.Instance.Id
);
throw;
}
}

Copilot is powered by AI and may make mistakes. Always verify output.
@bjorntore
Copy link
Contributor Author

/publish

@github-actions
Copy link

github-actions bot commented Oct 30, 2025

PR release:

⚙️ Building...
✅ Done!

@bjorntore
Copy link
Contributor Author

/publish

@github-actions
Copy link

github-actions bot commented Oct 31, 2025

PR release:

⚙️ Building...
✅ Done!

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
51.7% Coverage on New Code (required ≥ 65%)
47.5% Condition Coverage on New Code (required ≥ 65%)

See analysis details on SonarQube Cloud

@bjorntore
Copy link
Contributor Author

/publish

@github-actions
Copy link

github-actions bot commented Nov 3, 2025

PR release:

⚙️ Building...
✅ Done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-ignore This PR is a new feature and should not be cherry-picked onto release branches feature Label Pull requests with new features. Used when generation releasenotes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant