#1 2012-12-14 20:46:11

h.hasenack
Member
From: Nijmegen, Netherlands
Registered: 2012-08-01
Posts: 173
Website

Add/Update failed. How do I foind out why

I can find out using my debugger, but it would be so much better to have an 'GetLastError' solution, or maybe have an exception at client side raised that contains info about WHY the update failed.

Errors can haCOuld be e.g.
* the database rejected (key violation, invalid data etc) the update from the mOrmot
* mormot rejected the data
* communication failure/dropout

Currently it is quite hard (clienty side) to find out .

SUggestion:

find a way to catch/hold on to the "last" server side exception / exception message, and send it over to the client, either directly with the reply (not preferred due to bandwith considerations) or (preferably) in for form of a GetLastMotmotError:UTF8string / raiseLastMormotError solution that queries the server for the last exception/error info.


Hans

Offline

#2 2012-12-15 11:05:48

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Add/Update failed. How do I foind out why

Good idea.

I've added a task to the RoadMap:

Refactor the Client-Server error process, with better transmission of the error raised on server side to identify the cause of a failure on client side;

See http://synopse.info/fossil/wiki?name=RoadMap

Offline

#3 2012-12-15 12:37:26

h.hasenack
Member
From: Nijmegen, Netherlands
Registered: 2012-08-01
Posts: 173
Website

Re: Add/Update failed. How do I foind out why

Gr8!

Offline

#4 2013-01-24 08:55:51

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Add/Update failed. How do I foind out why

Offline

#5 2013-01-24 16:07:23

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,571
Website

Re: Add/Update failed. How do I foind out why

I also need this feature. For example in TSQLDBConnection.NewStatementPrepared database error go to nowhere. So it's impossible to get  error message been raised on database level (only in log files). Aa solution may be add "var Err" to

function TSQLDBConnection.NewStatementPrepared(const aSQL: RawUTF8;
  ExpectResults: Boolean; var Err: RawUTF8): TSQLDBStatement;
begin
  try
    result := NewStatement;
    result.Prepare(aSQL,ExpectResults);
  except
    on E: Exception do
      FreeAndNil(result);
      Err := StringToUTF8(E.Message)
  end;
end;

and push it up to NewThreadSafeStatementPrepared level?

Offline

#6 2013-01-30 13:33:30

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Add/Update failed. How do I foind out why

1. I've added TSQLRestClientURI.LastErrorCode/LastErrorMessage/LastErrorException properties, to retrieve additional information about remote URL() execution.
It will allow to retrieve the error on client side, as returned by the RESTful request.
See http://synopse.info/fossil/info/f2733cdb53

2. I've added RaiseExceptionOnError: boolean=false optional parameter to TSQLDBConnection.NewStatementPrepared() method, and  TSQLDBConnection.LastErrorMessage and LastErrorException properties, to retrieve the error when NewStatementPrepared() returned nil.
This would help to better handle errors in SynDB* units, as mpv expected.
See http://synopse.info/fossil/info/5f4d9a1c8b

Feedback is welcome.

Offline

#7 2013-01-30 14:40:51

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,571
Website

Re: Add/Update failed. How do I foind out why

O! This is very good.

Offline

#8 2013-02-01 16:41:21

Roberto Schneiders
Member
From: Santa Catarina, Brazil
Registered: 2012-09-19
Posts: 127
Website

Re: Add/Update failed. How do I foind out why

Thanks Arnaud.

I have some questions.

I just do not know when the server connection is working or not.

I have this code:

Client:= TSQLHttpClient.Create = ('127 .0.0.1 ', '888', Model);

Is there any way to test if a connection to the server is ok?

In the example that I put in this post http://synopse.info/forum/viewtopic.php?id=1053
There is still no solution for this, right?

Offline

#9 2013-02-01 18:53:49

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Add/Update failed. How do I foind out why

Just check the LastErrorException property if the method returned FALSE or 0 (meaning error): you should have a timeout exception here.

There is no such "ping" feature available, due to the nature of HTTP clients.

Offline

#10 2013-02-01 19:16:11

Roberto Schneiders
Member
From: Santa Catarina, Brazil
Registered: 2012-09-19
Posts: 127
Website

Re: Add/Update failed. How do I foind out why

I just do not have the server started.

After this line

Client:= TSQLHttpClient.Create = ('127 .0.0.1 ', '888', Model);

the Client.LastErrorException is nil.

Offline

#11 2013-02-01 20:49:13

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Add/Update failed. How do I foind out why

TSQLHttpClient.Create() does not make any connection attempt.
You need to perform a remote RESTful command to connect.

I've just made a fix to TSQLHttpClientGeneric.InternalURI() method in order to raise an explicit exception on connection error.
See http://synopse.info/fossil/info/5721ad49cf

Now Client.ErrorMessage='Server not available (System Error.  Code: 12029.)' for instance, with fLastErrorException=EOSError for TSQLHttpClientWinHTTP kind of connection.

So you can make such tests:

    Client := TSQLHttpClient.Create('localhost','888',Model);
    if not Client.SetUser('User','synopse') then begin
      ShowMessage(UTF8ToString(Client.LastErrorMessage));
      exit;
    end;

If you want just to test the connection, you can try the newly added TSQLRestClientURI.ServerTimeStampSynchronize method.
See http://synopse.info/fossil/info/900710ea17

Thanks for the feedback.

Offline

#12 2013-02-01 20:57:46

Junior/RO
Member
Registered: 2011-05-13
Posts: 210

Re: Add/Update failed. How do I foind out why

Great! Good work. I was waiting for some code like this too smile

Last edited by Junior/RO (2013-02-01 20:58:09)

Offline

Board footer

Powered by FluxBB