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

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 about 7 hours ago

To address the flagged issue, replace the generic catch (Exception ex) clause with catch clauses for more specific, expected exception types that can arise during the data deletion operation. In this context, exceptions such as IOException, OperationCanceledException, and possible lower-level service exceptions are likely relevant. For catch-all error logging (if truly necessary), use a separate clause but avoid catching System.Exception directly unless there's a strong justification.

Recommended changes:

  • In SubformPdfServiceTask.cs, in the foreach deleting existing PDFs, replace the catch (Exception ex) clause with specific exception types:
    • Consider OperationCanceledException for cancellation scenarios.
    • Consider IOException or System.Net.Http.HttpRequestException for network/file issues.
    • If a custom exception is thrown by dataClient.DeleteData, catch that.
  • Optionally, rethrow unexpected exceptions after logging or avoid catching them entirely.

No imports are necessary for these standard exception types as they are available in the .NET BCL.

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
@@ -134,15 +134,34 @@
                             instance.Id
                         );
                     }
-                    catch (Exception ex)
+                    catch (OperationCanceledException ex)
                     {
                         logger.LogWarning(
                             ex,
-                            "Failed to delete existing subform PDF {DataElementId} from instance {InstanceId}",
+                            "Data deletion for subform PDF {DataElementId} in instance {InstanceId} was canceled",
                             pdf.Id,
                             instance.Id
                         );
                     }
+                    catch (System.IO.IOException ex)
+                    {
+                        logger.LogWarning(
+                            ex,
+                            "I/O error deleting subform PDF {DataElementId} from instance {InstanceId}",
+                            pdf.Id,
+                            instance.Id
+                        );
+                    }
+                    catch (System.Net.Http.HttpRequestException ex)
+                    {
+                        logger.LogWarning(
+                            ex,
+                            "HTTP request error while deleting subform PDF {DataElementId} from instance {InstanceId}",
+                            pdf.Id,
+                            instance.Id
+                        );
+                    }
+                    // Optionally add more specific exception handlers here as necessary
                 }
             }
         }
EOF
@@ -134,15 +134,34 @@
instance.Id
);
}
catch (Exception ex)
catch (OperationCanceledException ex)
{
logger.LogWarning(
ex,
"Failed to delete existing subform PDF {DataElementId} from instance {InstanceId}",
"Data deletion for subform PDF {DataElementId} in instance {InstanceId} was canceled",
pdf.Id,
instance.Id
);
}
catch (System.IO.IOException ex)
{
logger.LogWarning(
ex,
"I/O error deleting subform PDF {DataElementId} from instance {InstanceId}",
pdf.Id,
instance.Id
);
}
catch (System.Net.Http.HttpRequestException ex)
{
logger.LogWarning(
ex,
"HTTP request error while deleting subform PDF {DataElementId} from instance {InstanceId}",
pdf.Id,
instance.Id
);
}
// Optionally add more specific exception handlers here as necessary
}
}
}
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 about 7 hours ago

To fix this problem, replace the generic catch (Exception ex) clause with catch blocks targeting only the exception types we expect and want to handle—typically IOException, TaskCanceledException, or possibly FormatException due to Guid.Parse/data issues. Any unexpected exceptions (such as NullReferenceException, OutOfMemoryException, or other fatal errors) should be allowed to propagate.

How to fix:

  • Replace the generic catch (Exception ex) at line 149 with targeted catch blocks for expected exception types.
  • Add one or more specific catch blocks (for example, catch (TaskCanceledException), catch (FormatException), catch (IOException) if appropriate), each with appropriate logging.
  • If there is a truly compelling reason to suppress all exceptions, document the justification in a comment.
  • Otherwise, add a final catch that rethrows unexpected exceptions, or remove the broad catch altogether.

What is needed:

  • No new methods or definitions.
  • No additional imports required.
  • Only changes within the body of CleanupExistingSubformPdfs.

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
@@ -146,14 +146,24 @@
                 }
             }
         }
-        catch (Exception ex)
+        catch (TaskCanceledException ex)
         {
             logger.LogWarning(
                 ex,
-                "Error during subform PDF cleanup in instance {InstanceId}",
+                "Subform PDF cleanup was canceled in instance {InstanceId}",
                 context.InstanceDataMutator.Instance.Id
             );
         }
+        catch (FormatException ex)
+        {
+            logger.LogWarning(
+                ex,
+                "Subform PDF cleanup encountered invalid GUID format in instance {InstanceId}",
+                context.InstanceDataMutator.Instance.Id
+            );
+        }
+        // Catch other anticipated exceptions as needed.
+        // If desired, add a comment explaining why not all exceptions are caught.
     }
 
     private async Task AddSubformPdfMetadata(
EOF
@@ -146,14 +146,24 @@
}
}
}
catch (Exception ex)
catch (TaskCanceledException ex)
{
logger.LogWarning(
ex,
"Error during subform PDF cleanup in instance {InstanceId}",
"Subform PDF cleanup was canceled in instance {InstanceId}",
context.InstanceDataMutator.Instance.Id
);
}
catch (FormatException ex)
{
logger.LogWarning(
ex,
"Subform PDF cleanup encountered invalid GUID format in instance {InstanceId}",
context.InstanceDataMutator.Instance.Id
);
}
// Catch other anticipated exceptions as needed.
// If desired, add a comment explaining why not all exceptions are caught.
}

private async Task AddSubformPdfMetadata(
Copilot is powered by AI and may make mistakes. Always verify output.
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
51.0% 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 Oct 30, 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