I am in a BeforePost event handler hoping to cancel the post before it goes through. At the end of my BeforePost function I call DataSet->Cancel(); and when debugging through this I see it go from my function to the TDataSet.DoBeforePost function then to the TDataSet.Post; where it calls CheckOperation(). CheckOperation throws an exception (which I tried to avoid by calling Cancel() ) because the data is incorrectly entered and the user sees this error.
Is there something in this order of operations that I am doing wrong? Any kind of ideas or guidance would be greatly appreciated.
If I remember correctly then you should use Abort() instead of Cancel();
Related
In Protractor tests I call many times browser.wait method for example to wait once the particular element will appear on the screen or it will be clickable.
In many cases tests passes on my local machine, but does not on other.
I receive very generic information about the timeout which doesn't help me a lot to debug / find a source of issue.
Is it possible to make a browser.wait more verbose, for example:
if at least defaultTimeoutInterval will elapse when waiting for particular element, will it be possible to console.log information about the element that it tried to wait for,
take a screenshot when the timeout error occurs,
provide full call stack when timeout appears in browser.wait
If the main issue is that you don't know for which element the wait timed out, I would suggest writing a helper function for wait and use it instead of wait, something like:
wait = function(variable, variableName,waitingTime){
console.log('Waiting for ' + variableName);
browser.wait(protractor.ExpectedConditions.elementToBeClickable(variablename),waitingTime);
console.log('Success');
}
Because protractor stops executing test after first fail, if wait timed out, console won't print success message after failing to load a certain element.
For screenshots I suggest trying out protractor-jasmine2-screenshot-reporter, it generates an easily readable html report with screenshots and debug information on failed tests (for example, in which code line the failure occured).
Look into using protractor's Expected Condition, you can specify what to wait for and how long to wait for it.
For screenshots there are npm modules out there that can take a screenshot when a test fails. This might help.
browser.wait returns a promise, so catch the error and print/throw something meaningful like:
await browser.wait(ExpectedConditions.visibilityOf(css), waitingTime).catch((error) =>
{
throw new CustomError(`Could not find ${css} ${error.message}`)
});
I am working on some modifications to EEGlab's eegplot function (things like vim-style navigation etc.) that need to work through WindowKeyPressFcn.
However, the callback is not being called for some reason. I have been debugging the issue for some time and am a bit lost. I am looking for suggestions on what might be wrong. Unfortunatelly the eegplot function is big, complex and somewhat convoluted and I was unable to reproduce the issue in a simple example. Therefore I am looking for general suggestions on why a function handle that is clearly present in WindowKeyPressFcn might stop being used at some point.
Here is what I have learned so far:
If I go to debug mode in eegplot (set a breakpoint near the end of the setup function [the first half of eegplot]) I am able to run the WindowKeyPressFcn at least once.
However - the function stops being called at some point during debug (sometimes even after being called only once).
If I run eegplot without debug (that is wait for it to finish and return control to me) I am unable to call WindowKeyPressFcn by pressing a key. The function handle is still present in WindowKeyPressFcn property of the figure.
Whener the WindowKeyPressFcn is not being used when I press a key, I can still call it with:
figh = gcf;
fun = get(figh, 'WindowKeyPressFcn');
ev.Key = 'rightarrow';
ev.Character = ' ';
ev.Modifier = [];
feval(fun, figh, ev);
So the function handle is 'healthy' so to speak, but for some reason it is not being used any more when a key is pressed and the figure has focus. When and why something like this could happen? Any ideas on things I should check to understand this issue?
Update:
I found out that WindowKeyPressFcn callback can sometimes be blocked by some window listeners, and tried out the following solution:
hManager = uigetmodemanager(gcf);
set(hManager.WindowListenerHandles,'Enable','off');
It doesn't work - WindowKeyPressFcn is still not called when I press a key. :(
Update 2:
Another thing that does not work:
chld = get(gcf, 'Children');
tp = get(chld, 'type');
chld = chld(strcmp(tp, 'uicontrol'));
set(chld, 'KeyPressFcn', #eegplot_readkey_new)
(eegplot_readkey_new is the function I use for reacting to keypresses)
Update 3:
And another one not working:
addlistener(gcf, 'WindowKeyPress', #eegplot_readkey_new);
Ok - I fiugred it out, although the solution is weird to say the least.
For some mysterious reason using linesmoothing undocummented property prevents WindowKeyPressFcn from being called. I have absolutely no idea why...
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
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);
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.