StrSubstNo or string concatenation must not be used as a parameter in the Error method
Title StrSubstNo or string concatenation must not be used as a parameter in the Error method.
Description The data classification context will be lost when using the StrSubstNo method or string concatenation as a parameter in the Error method. Instead use the ability of the Error method to insert values into the string with placeholders.
Reason for the rule All error messages are logged into telemetry and we do not allow adding customer data into telemetry. So all error that have a textconst as first argument actually log the textconst in telemetry, this greatly increase that ability to resolve errors found in telemetry. If StrSubstNo or string concatenation is used as first argument the data classification context is lost and no message text is logged in telemetry.
Bad code sample 1
var
ErrorMsg: Label 'Customer %1 has incorrect email', Comment = '%1 = Customer No.';
local procedure MyProcedure()
begin
Error(StrSubstNo(ErrorMsg, Customer."No.");
end;
Good code sample 1
var
ErrorMsg: Label 'Customer %1 has incorrect email', Comment = '%1 = Customer No.';
local procedure MyProcedure()
begin
Error(ErrorMsg, Customer."No.");
end;
Bad code sample 2
var
Text000Err: Label 'There are no planning lines to make orders for. ';
Text007Err: Label 'This template and worksheet are currently active. ';
local procedure MyProcedure()
begin
Error(Text000Err + Text007Err);
end;
Good code sample 2
var
ErrorMsg: Label 'There are no planning lines to make orders for. This template and worksheet are currently active. ';
local procedure MyProcedure()
begin
Error(ErrorMsg);
end;
Good and bad practices for fixing the rule Use ability of Error method to insert values (expressions) into the string that has placeholder.
Remarks None
I think Bad code sample 2 is actually not bad at all. I see following use case:
var
Text000Err: Label 'There are no planning lines to make orders for. ';
Text007Err: Label 'This template and worksheet are currently active. ';
Text008Err: Label 'Something else has been found as a show stoper.';
local procedure MyProcedure()
begin
if Check1 then
Error(Text000Err + Text007Err)
else if Check2 then
Error(Text000Err + Text008Err)
end;
The goal is to reuse the First Text Constant (Text000Err).
For translation I would tend to agree in the cases where it is 2 separate sentences. But still in other case you might still keep them together to ease translation.
For the purpose of this rule you will loose the error into from the telemetry al together.
I didn't understand the comment about the telemetry. In which case and what is lost in Telemetry?
We only get the error test in Telemetry if the first argument is a label or a textconst.
Thank you for reporting this issue. Unfortunately, we do not find is important enough to address at this point.