Use Error with ErrorInfo or Label instead of Text

Properties
LC0048 Warning Design Code Fix Ignore Obsolete

When the Error method is called in Business Central, the platform emits an RT0030 telemetry signal to Azure Application Insights. The alErrorMessage dimension of that signal carries the actual error text — but only when the first argument is a Label, TextConst, or ErrorInfo:

The actual error string from AL code is shown in this dimension only if the string is a Label or TextConst data type. For all other data types, the string Use ERROR with a text constant to improve telemetry details is shown instead of the actual string.

Analyzing Error method telemetry on Microsoft Learn

Passing a string literal, a Text variable, or a StrSubstNo expression strips the real message from telemetry. When you investigate errors in Application Insights, all you see is the generic placeholder — making it impossible to diagnose the issue without reproducing it.

Pass a Label variable directly to Error, or use an ErrorInfo object.

Example

The following code passes a string literal to Error:

procedure ValidateAmount(Amount: Decimal)
begin
    if Amount < 0 then
        Error('Amount cannot be negative'); // Use Error with ErrorInfo or Label instead of Text [LC0048]
end;

Declare the message as a Label variable and pass it to Error:

procedure ValidateAmount(Amount: Decimal)
var
    AmountCannotBeNegativeErr: Label 'Amount cannot be negative';
begin
    if Amount < 0 then
        Error(AmountCannotBeNegativeErr);
end;

A common mistake is wrapping a Label in StrSubstNo before passing it to Error. Because StrSubstNo returns Text, the message is still stripped from telemetry — even though the format string is a Label:

procedure ValidateCustomer(Customer: Record Customer)
var
    NotValidCustomerErr: Label '%1 is not a valid customer.';
begin
    if not Customer.Find() then
        Error(StrSubstNo(NotValidCustomerErr, Customer.Name)); // Use Error with ErrorInfo or Label instead of Text [LC0048]
end;

Error has built-in placeholder substitution — pass the Label and its arguments directly:

procedure ValidateCustomer(Customer: Record Customer)
var
    NotValidCustomerErr: Label '%1 is not a valid customer.';
begin
    if not Customer.Find() then
        Error(NotValidCustomerErr, Customer.Name);
end;

As an alternative, pass an ErrorInfo object. Use Label for straightforward error messages; use ErrorInfo when you need actionable errors , custom dimensions, or data classification:

procedure HandleError()
var
    MyErrorInfo: ErrorInfo;
begin
    if not TryDoSomething() then begin
        MyErrorInfo := ErrorInfo.Create(GetLastErrorText());
        Error(MyErrorInfo);
    end;
end;

When the diagnostic is reported

  • The first argument to Error is a string literal (e.g., Error('message')).
  • The first argument is a Text variable.
  • The first argument is a StrSubstNo expression, even when its format string is a Label.

Error('') (empty string literal) does not trigger the diagnostic.

See also