-
Notifications
You must be signed in to change notification settings - Fork 22
WIP: Feat/subform service task #1512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…eration and eFormidling.
…ult enum and use result classes instead, for expandability.
…elds from result class and instead return generic failed ProcessChangeResult.
…served key word Next.
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing touches🧪 Generate unit tests (beta)
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. Comment |
|
/publish |
PR release:
|
|
/publish |
|
/publish |
PR release:
|
# 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
| 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
Show autofix suggestion
Hide autofix suggestion
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 rethrowsOperationCanceledException. - 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
Systemis available.
-
Copy modified lines R136-R139
| @@ -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}", |
| 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
Show autofix suggestion
Hide autofix suggestion
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.
-
Copy modified lines R146-R154 -
Copy modified line R159 -
Copy modified line R162
| @@ -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; | ||
| } | ||
| } | ||
|
|
|
/publish |
PR release:
|
src/Altinn.App.Core/Internal/Process/ProcessTasks/ServiceTasks/SubformPdfServiceTask.cs
Fixed
Show fixed
Hide fixed
|
/publish |
PR release:
|
|
|
/publish |
PR release:
|


Description
Related Issue(s)
Verification
Documentation