TMS MQTT could be silent errors implemented?

Hello everyone,

I encounter a typical error when attempting to use the publish method before the client is connected to the broker:

"This action requires a connected state..."

I understand the necessity of this requirement, but would it be possible to implement silent error handling through an additional component property? Ideally, an OnError() event for the component would greatly enhance usability. If the user does not connect their own handler, errors would be handled as before. However, by connecting my OnError() handler, no pop-up window with error information would appear. It's extremely inconvenient not being able to implement custom error handling, without having to resort to adding a "try ... except" block in the code for EVERY call to publish, subscribe, and for every other potential error situation.

Could we expect such a minor modification to be introduced?

Best regards, Mirek

Did you try to add a

try
except
end;

around it at application level to catch this exception if you do not want to see it?

But I wrote above that it is very inconvenient to keep using
try... except... end;
in many places in the program.

Yes, I confirm that it works and it is the only solution at the moment, unfortunately.

However, I would like to make a small suggestion that the developers should add silent error handling - I always do this in my components.

One additional event is enough for example:

OnError( error_id: Integer; error_msg: string );

and that would be the end of the problem.

We'll reflect on this and monitor other users feedback to make a well informed decision.

I would like to kindly ask you to add this option to the component. It is very simple to make it so that errors are reported by default as before for ordinary users who do not use components in an advanced way.

I'm writing large software, and believe me, adding sections over and over again:

try
except
end

it is very burdensome and, what is worse, it does not solve all situations. Please believe me that the so-called "SILENT ERRORS" option is used very widely around the world in various Delphi components. In such an event to handle silent errors, I can react in one place in the code as I like, depending on the project. Otherwise, in my huge project where I use a lot of calls: publisch, subscribe, unsubscribe etc... my code starts to swell mercilessly with "try...except...end"

Moreover, when such an opportunity becomes available, I bet that many users who have not reported such a need so far will be happy to use it.

Thank you in advance for adding this functionality. Moreover, if necessary, I am ready to help in adding this option to the component, as long as this functionality is considered standard in subsequent versions.

I'm not sure it is desirable to hide errors. If at all it is possible to resume functioning correct after an error occurred. As I said, we'll reflect about this and monitor.

Hi ...
May I suggest you use some kind of wrapper or even an object helper while this OnError functionallity is not available? This way you could call your helper methods or some wrapper-kind methods with dependency injection, instead of calling directly the component's Publish, Subscribe & etc ... Your customized code would have the try..except blocks, without flooding it over the whole application code.
Then, when the component gets updated (or not), you'll only have to retouch those customized methods i/o all the app code.

please look very very simple example:

type

  TTMSMQTTOnError = procedure(Sender: TObject; Error: Integer; Desc: String) of object;

...

  TTMSMQTTClient = class(TComponent)
  private
  ...

    FOnErrorID: Integer;
    FOnErrorDesc: String;
    FOnError: TTMSMQTTOnError;
   ...

  protected

   procedure DoOnError; virtual;
   ...


  published

    property OnError: TTMSMQTTOnError read FOnError write FOnError;
   ...


procedure TTMSMQTTClient.DoOnError;
begin
  if Assigned(FOnError) then FOnError(self, FOnErrorID, FOnErrorDesc);
end;

and for example somewhere in componnet source:

function TTMSMQTTClient.Publish(ATopic: string; APayload: TBytes; var APacketID: Word; AQos: TTMSMQTTQoS; ARetain, ADuplicate: Boolean): boolean;
var
  packet: TTMSMQTTPublishPacket;
  i: integer;
  LPublishProperties: TTMSMQTTPublishProperties;
begin

  // check if we are connected:
  if not Assigned(FOnError) then
    AssertConnectedState; // <---- YOUR METHOD - you rise error with your popup and text

  // simple method for silent errors
  if not Session.HasActiveMqttConnection then begin
    FOnErrorID := 100;
    FOnErrorDesc := 'Session has not Active Connection';
    DoOnError;  // <--- here is my method - silent error
    Exit;
  end;

  ...

Belive me it's working great. If anyone not implement OnError Method in MQTTclient we have asserttion like in your code, but if I imlement my OnError Method, for example:

procedure TForm1.OnMQTTerror( Sender: TObject; Error: Integer; Desc: String );
begin
   // NOW I CAN handle errors in my own way
    MemoTX.Lines.Add( 'Error# '+IntToStr(Error) + ' Description: '+Desc );
end;

I can handle errors in my own way for my project.

Yes I can but look please how it's simple to implement silent errors inside MQTT componnent. Then I can handle all errors in my own way without any helpers, and try-except etc