microsoft / BCApps

Repository for collaboration on Microsoft Dynamics 365 Business Central applications.
https://microsoft.github.io/BCApps/
MIT License
267 stars 125 forks source link

[BC Idea]: #1484

Open StefanMaron opened 3 days ago

StefanMaron commented 3 days ago

BC Idea Link

https://experience.dynamics.com/ideas/idea/?ideaid=57c2f6a4-ca39-ef11-a295-6045bd84c2f2

Description

I often find myself raising errors the "old way with Error('some error message'); just because its so much easier to type.

The idea is to create a wrapper codeunit with all the procedures build in a way that every aspect of the ErrorInfo type is optional via parameters, and every function will return the ErrorInfo type.

That way we can easily create an ErrorInfo object inline without the need to create long functions.

Example:

Error(
    ErrorInfo.Create()
        .Message('Something went wrong')
        .SetTableId(Database::MyTable)
        .AddNavigationAction('ShowMe')
        .AddAction('FixIt',Codeunit::FixErrorHelper, 'FixTheError')
);

For complex scenarios, this wont improve readability of course, and its not the intention of course, its more to make it easier to uptake ErrorInfo more easily.

I will provide the implementation for this BC Idea

guidorobben commented 3 days ago

Great idea.

StefanMaron commented 3 days ago

I created an implementation for this already:

https://github.com/StefanMaron/ErrorInfoWrapper

guidorobben commented 3 days ago

Looks great on first sight.