Report logical errors to catch business rules violations

posted by jgauffin 2 years ago

Logical errors are errors that you can recover from but have to be corrected in future application versions. Before, you had to generate an exception to be able to report those errors in Coderr. In this version, we have introduced a new API to report that kind of errors.

Example 1 – Report network trouble

Let’s assume that you have code that uses the network to communicate between the server and the clients. You expect the network to respond in a timely fashion and not drop packets. To be safe, you added code to make sure that everything is delivered even though the network is flaky. As you already have handled that case, there is no need to throw exceptions and deal with them. But you still want to get information when there is network trouble.

With the latest Coderr client, report the error with:

Err.ReportLogicError(“Network dropped packets”);

As usual, you can include context data with the error:

Err.ReportLogicError(“Network dropped packets”, new { destination: DestinationIp, packet: dto });

It will appear among all other errors, but with the tag “logical-error” to make it easy to filter on those errors.


Example 2 – User do not follow the designed flow

You have built an excellent todo application which prioritizes tasks based on the individual work pattern of each user. However, sometimes the user skips a few steps which mess up your algorithm. To learn what the user does to be able to improve the algorithm you want to record how often the user breaks the designed flow.

Your application can still recover from that by adding the missing steps. Thus it’s not an exception but also not an optimal usage of your application.

As in the previous example, you can use ReportLogicalError.

Err.ReportLogicalError(“User skipped step “ + stepName, new {user, newStep });

However, as no exception is available, Coderr need to use something else to report the error. In this case, it’s the message. But as the message varies, it will generate duplicate errors. To mitigate that you can use a third parameter as error identifier:

Err.ReportLogicalError(“User skipped step “ + stepName, new {user, newStep }, “SkipStep” + stepName);

That’s fantastic since we now get an error per skipped step which also helps us see how often a certain step is skipped.


When using the partitioning feature in Coderr Live and Coderr Premise we can also see the percentage of the users that skipped a specific step.


With this feature you can prioritize logical errors based on facts and impact instead of the personal opinion from one of the team members. It makes it easier to know if you should focus on building new features instead of correcting this kind of bugs.

The client libraries (v1.1 of Coderr.Client and v1.2 of Coderr.Client.NetStd) already supports this feature. As do Coderr Live and Coderr Premise. It also exists as a commit in the Community Server repository and will be available when Coderr Community Server v2.0 is released.