Repository navigation
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds two LinterCop rules that flag database modifications inside a
[TryFunction].A TryFunction swallows runtime errors, but it does not roll back database writes made before the error. Code that writes inside a TryFunction can therefore leave the database half-updated while the caller carries on as if the call had failed cleanly.
TryFunctionDatabaseModificationDisallowedTryFunctionPotentialDatabaseModificationBoth are enabled by default. Neither has a CodeFix, a setting or a version gate.
What is reported
LC0101 (Error) is raised on built-in methods that always write:
Insert,Modify,ModifyAll,Delete,DeleteAll,Rename,Truncate,AddLink,CopyLinks,DeleteLink,DeleteLinks.LC0102 (Warning) is raised on calls that may write, depending on the target:
Validate, since field triggers may modify dataRunandCodeunit.RunDeliberate limits
FieldRef.Validateis covered by the same rule asRecord.Validate.Implementation notes
TryFunctionDatabaseModification, registered withRegisterCodeBlockAction. It reports both diagnostics in the same callback and carries no state between callbacks.MethodDeclarationSyntax.IsTryFunction(), becauseIMethodSymbol.IsTryFunctionis not available onnetstandard2.1.ALCops.Common.RecordMethodClassification, and the remaining names are listed in the analyzer.Tests
5 new fixture-based tests:
HasDiagnostic: all 11 direct modification methods, and the potential-modification cases.NoDiagnostic: read-only methods, the same calls outside a TryFunction, and an obsolete TryFunction.Validation:
ContinuousIntegrationBuild=true: succeeds onnetstandard2.1,net8.0andnet10.0.dotnet format --verify-no-changes: clean.Validate-Rules.ps1: passes.Documentation
.claude/rules/diagnostics/lc0101-lc0102-tryfunction-database-modification.md.alcops.dev(content/docs/analyzers/lintercop/LC0101.mdandLC0102.md) still need to be written.