BusinessCentral.LinterCop icon indicating copy to clipboard operation
BusinessCentral.LinterCop copied to clipboard

Add LC0054: Warning on database operations in TryFunctions

Open StefanMaron opened this issue 1 year ago • 4 comments

StefanMaron avatar Feb 12 '24 05:02 StefanMaron

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." ?

Arthurvdv avatar Feb 12 '24 08:02 Arthurvdv

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.

jwikman avatar Feb 23 '24 16:02 jwikman

Yes, but I did not find a way to find those type of scenarios unfortunately

StefanMaron avatar Feb 23 '24 17:02 StefanMaron

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... :)

jwikman avatar Feb 23 '24 17:02 jwikman

@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?

Arthurvdv avatar Jun 01 '24 18:06 Arthurvdv

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.

Arthurvdv avatar Jun 29 '24 09:06 Arthurvdv