SocketError handling in Prolog - sockets

I'm a bit unfamiliar with the mechanics of error recovery in prolog, so I apologize in advance if the question seems stupid.
I am looking for a way to properly handle SocketError in swi-prolog. So far I have only found the following snippet:
setup_call_catcher_cleanup(tcp_socket(Socket),
tcp_connect(Socket, Host:Port),
exception(_),
tcp_close_socket(Socket)).
Whenever a connection is refused, it raises the appropriate exception and performs the cleanup action, closing the socket.
Problem is, i want to embed this in a predicate test_socket/3 that sets a status code whenever a connection gets refused and I cannot seem to find a way to do so. I tried doing:
test_socket(Host, Port, Status) :-
setup_call_catcher_cleanup(tcp_socket(Socket),
tcp_connect(Socket, Host:Port),
exception(_),
(tcp_close_socket(Socket), Status = 1).
but this doesn't seem to do the trick. Any ideas?

The purpose of the argument Cleanup is to perform some cleanup action, and then to continue, as if this cleanup has not happened. That is, the exception goes further up and Status = 1 is superfluous. The construct is not made to do everything. But probably a catch/3 above all of this, is what you want.
– false

Related

[ script:es_extended SCRIPT ERROR: #es_extended/server/functions.lua:127: attempt to index a nil value (local 'xPlayer')

[ script:es_extended] SCRIPT ERROR: #es_extended/server/functions.lua:127: attempt to index a nil value (local 'xPlayer')
[ script:es_extended] > ref (#es_extended/server/functions.lua:127)
Please help me im triggered af Thats my Fivem Console (TxAdmin) Nothing works Esx is completly broke after a server Restart
I had a look at the source code. My best guess is that the player you are using isn't registered in the MySQL database for some reason.
I am guessing this because of the following:
The immediate cause of the error is that xPlayer is nil in server/functions.lua:127
This is due to the player object not being added to the ESX.Players table in server/main.lua:239
The info necessary to make the player object is taken from MySQL on server/main.lua:115
So the most obvious explanation would be that the user wasn't found in the database. It is also possible that the program could not connect to the database at all, but it looks like the fivem-mysql-async library would raise an error instead of continuing silently, so that is less likely (although this would need testing to discount completely).
Are there any messages in the server logs that might give you a clue as to what's going on?

How to Troubleshoot Dexie bound on IDBKeyRange Error

I'm using Dexie.js version 3.0.3-rc.3 in a Vue JS project and I occasionally run into this exception in Chrome (86):
Failed to execute 'bound' on 'IDBKeyRange': The parameter is not a valid key.↵ DataError: Failed to execute 'bound' on 'IDBKeyRange': The parameter is not a valid key.
Here's a screenshot of the full error:
I'm fairly certain the problem lies with something in my data being undefined, but I'm trying to find a good way to troubleshoot this. I paused the Chrome dev tools on exceptions and inspected the code around this particular part of Dexie, but it doesn't reveal what data was used to make this exception occur.
Does anyone have any suggestions on how to find out what's actually wrong? It feels a bit like a needle in a haystack.
== Update ==
Below is the full call stack:
Try inspecting the call stack. I know it can be long until you reach a frame within your application code, but the failing call should be there!

Calling a method from ABL code not working

When I create a new quote from Epicor I would like to add an item from the parts form automatically.
I am trying to do this using the following ABL code which runs when 'GetNewQuoteHed' is called:
run Update.
run GetNewQuoteDtl.
run ChangePartNumMaster("Rod Tube").
ttQuoteDtl.OrderQty = 5.
run Update.
I am getting the error:
Index -1 is either negative or above rows count.
This error occurs for each line in my ABL code.
What am I doing wrong?
That's not the proper format for a 4GL error message (nor is it at all familiar) so I'd say it is an Epicor application message. Epicor support is probably your best bet. However... Just guessing but it sounds like you might need to somehow initialize the thing that you're updating.
Agree with #Tom, but i would also say try and isolate the error and see where the error is raised as soon as you find the point the error is actually raised it is normally much easier to figure out exactly what is going wrong and how to solve it.
Working between a 0 based and a 1 based system there can be issues with the 1st or last entry depending on which way you moving. As the index for 0 based systems starts at 0 and ends at n-1 where 1 based systems start at 1 and end at n.

Indy - ReadLnSplit Causes NotConnected Exception when closing

I use TIdTCPServer and the following code to read client input :
repeat
cl3:=cl3+AContext.Connection.IOHandler.ReadLnSplit(WasSplit,#0,-1,-1,TEncoding.UTF8);
until not WasSplit;
However if client is connected to the server and I close the server it raises an exception class (EIdNotConnected) whith message 'Not connected'.
If I use ReadLn instead ReadLnSplit no exception raises.
What causes this exception and how could I prevent it?
I suppose the solution is simple but I am new to sockets and Indy and I cant figure it out.
Thanks in advance.
What is the actual problem? When you close the server, it is supposed to make active reading/writing operations raise an exception. That is normal behavior for Indy. ReadLn() is just as likely to raise an exception as ReadLnSplit() is. Indy relies on exceptions for its internal notifications. Just let the server handle the exception for you, so it can terminate and cleanup the thread that is managing the TIdContext and its connection. The exception is in the context of that thread, the rest of your code (or your users) will not see it.
The only thing ReadLnSplit() does differently than ReadLn() is to force the IOHandler's MaxLineAction property to maSplit during that call, nothing else. The only reason to use ReadLnSplit() is to handle lines that are longer than the IOHandler's MaxLineLength property without changing the MaxLineLength. If you don't like the way ReadLnSplit() behaves, then don't use it. You could just increase the value of the IOHandler's MaxLineLength property and call ReadLn() instead:
AContext.Connection.IOHandler.MaxLineLength := MaxInt;
cl3 := AContext.Connection.IOHandler.ReadLn(#0, IndyUTF8Encoding);
Or you could call the overloaded version of ReadLn() that has an optional AMaxLineLength parameter:
cl3 := AContext.Connection.IOHandler.ReadLn(#0, IdTimeoutDefault, MaxInt, IndyUTF8Encoding);

NSStream Event Timer - iPhone

All,
Is there a way to have a minimum time to keep a stream open before it closes? For some reason, my stream is closing prematurely which is causing errors elsewhere. I need to keep it open to make sure ALL of the data is gathered, and then it can run the other code.
Thanks,
James
In the case that someone falls upon this question later, I ended up creating nested if statements to pull it off.
Basically, there is one statement that checks if the end tag is not found (for my code, the END of the ENTIRE data that I should be receiving is </SessionData> - So, I did if([outputString rangeOfString:#"</SessionData>"].location == NSNotFound). I created a string called totalOutput that would have the outputString added onto the end of totalOutput until the </SessionData> is found.
If anyone ever needs help, just go ahead and comment on here and I can give more information.