BusinessCentral.LinterCop
BusinessCentral.LinterCop copied to clipboard
Add LC0054: Warning on database operations in TryFunctions
Do not call write operations in try Functions Do not call any database operations in TryFunctions.
There may be some ambiguity if all database operations should be avoided or only database write operations?
https://learn.microsoft.com/en-us/previous-versions/dynamicsnav-2018-developer/Handling-Errors-by-Using-Try-Functions#DbWriteTransactions
If I understand de documentation correctly, only database write operations should be avoided.
Maybe "Do not call any database write
operations in TryFunctions." ?
I just love the idea with this rule!
It is very challenging to find these issues during code review, since a TryFunction
can call other functions that performs write operations.
Yes, but I did not find a way to find those type of scenarios unfortunately
Yes, but I did not find a way to find those type of scenarios unfortunately
Ok, I see. But good to get started on this rule anyway! Maybe we can update the rule one day, when we figure out how to... :)
@StefanMaron What should we do with this pull-request? Do we added the rule as-is and improve this in the future or abandon this PR and revert this back into an idea?
During TechDays in Antwerp we've discussed to close this PR. The main reason is that this is a complex rule to find all the references and walk though every chained method/procedure to find if there's somewhere a TryFunction in between. With the use of interfaces and/or public methods with dependency extensions, this will even be close to impossible to have a solid rule.