GetLastErrorText appears to be returning text different from the last thrown error under some circumstances for one of our clients running BC 18.8 On Premises. We have the following code for a document:
... Rec.SuspendStatusCheck(true); Rec."Count Process Retries" = 1; Rec."Last Error" := ''; Rec.Modify(); recInterfaceEntry."Last Error" := ''; recInterfaceEntry.Modify(); Commit(); ClearLastError(); if not Codeunit.Run(recInterfaceSetup."Inbound Transfer Codeunit", recInterfaceEntry) then begin str := CopyStr(GetLastErrorText(), 1, MaxStrLen(str)); recInterfaceEntry.Get(Rec."Interface Entry No."); recInterfaceEntry.WriteLog(str, recInterfaceEntry."Last Status"::TransferError); recInterfaceEntry."Last Error" := str; recInterfaceEntry.Modify(); ...
The executed codeunit starts a posting process, during which an error such as "Nothing to post" will occur. The error text is immediately copied to the variable str, and then logs them in a protocol table. The other day, our client logged multiple entries with an empty text. After some research, we could determine the error that caused the logs to be due to an invalid posting date, but this has been logged correctly in the past. When debugging on a test server, I noticed that breaks between the error and the GetLastErrorText causes the returned error message to be different. The origin of that error is unknown since the debugger doesn't break for any error except the one I'm expecting, and the message itself contains the name of a field that never appears in the project of our extension. Given that the actual server was never debugged, some other factor must have been at play, but I suspect these two incidents are related.
First of all, does GetLastErrorText return errors from only one session, or can it not delineate the origin of the error? Microsoft's official documentation of the GetLastErrorText-command confirms neither statement.
Second, could there be a different reason as to why GetLastErrorText would suddenly return an empty string? There are no other sections in our extension that add anything else with this Enum value as parameter, so it had to have come from the command.