Error override for successul fail - error-handling

I'm trying to override and error thrown by one of my command in my script.
I run a simple setup, which returns an error code of '1', which means it failed but I know that it was successful, so I would like for my script to return an exit code of '0' instead when this error is thrown.
THks in advance and don't hesitate if you have any questions.

Related

vba selenium waitDisplay method not working

Who can tell me why the method of Selenium WebDriver.WaitDisplayed is not working in my code below?
I can share other code if needed?
Set a = webdriber.FindElementsByClass("search-global-typeahead__collapsed-search-button")
a.Item(1).WaitDisplayed(True).Click ' operation timed out after -1ms. Run-time err'21'
a.Item(1).Click ' gives an error
I added code below; without successful result
a.Item(1).WaitDisplayed(True, 100).Until(a.Item(1).IsDisplayed,10)
I guess to start with the most obvious, does it still cause an error after fixing the typo in the 'webdriber' identifier? I'm guessing your declaration is spelled 'webdriver'.

Python: If error occurs anywhere, do specific line of code

I have a script I'm trying to write to process a large amount of data. There are, of course, potential for errors. In the script I need to connect to databases. If the script encounters an error, the code never reaches the point where the connection to the database is terminated. I'd like to have something in my python code that will recognize an error occurs, not matter where, and if nothing else at least close those databases. Does something like this exist? I know I can use try/except, but that would only work if I know exactly where I could get the error? I'm basically looking for a catchall to close my databases in the event an error occurs in a location I didn't anticipate.
To run certain cleanup code even if there is an error, use the finally block:
try:
# do stuff, possible exception
except:
# run this if exception
finally:
# always run this, even if exception
Reference: https://docs.python.org/3/tutorial/errors.html#defining-clean-up-actions

Value of type 'Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer' cannot be converted to 'System.Type

I'm working on a custom TFS Build workflow based on the code found in two blogs:
http://www.theringworx.com/blog/?p=494
https://lajak.wordpress.com/2011/08/30/tfs2010-retrieve-associated-workitems-to-changesets-tfs-api/
When I implement the VB.Net code within my XAML workflow, I'm currently getting the following errors on build runtime:
The build process failed validation. Details:
Validation Error: The private implementation of activity '1:
DynamicActivity' has the following validation error: Compiler
error(s) encountered processing expression "TFSService".
Value of type
'Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer'
cannot be converted to 'System.Type'.
Validation Error: The private implementation of activity '1:
DynamicActivity' has the following validation error: Compiler
error(s) encountered processing expression "TFS.GetService(Of
VersionControlServer)();".
End of expression expected.
I've traced the error down to this section of code (Simplified from XAML):
TFS=Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory.GetTeamProjectCollectionFactory(New Uri("MyTeamsTFSServer"))
TFSService = TFS.GetService(Of VersionControlServer)()
I've tried changing the type of TFSService from both Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer and System.Type without success.
From what I can tell the error is occurring in the "Of VersionControlServer".
Has anyone ever encountered this? And if so how did you resolve it?
Turns out the issue was the URL I was using, I made a typo when I was entering it in. Yay for descriptive error messages...
I found this while I was checking my authentication using the two methods:
TFS.HasAuthenticated
TFS.Authenticate();
My code blew out when I was running the Authenticate() method.

Writing Codeception CLI test; want to throw exception but not have it fail the test

I forked Codeception/Codeception and added a Command module check that throws an exception.
When testing, this exception causes the test to fail but I'm running a test to force the exception and failure, to make sure it catches it.
Here's the edit to src/Codeception/Command/GenerateSuite.php
if ($this->containsInvalidCharacters ($suite)) {
throw new \Exception("Suite name '{$suite}' contains invalid characters. ([A-Za-z0-9_]).");
}
When updating tests/cli/GenerateSuiteCept.php when I run the command $I->executeCommand('generate:suite invalid-suite'); it fails because I'm throwing the exception in src/Codeception/Command/GenerateSuite.php in the first place.
Here is the addition to tests/cli/GenerateSuiteCept.php:
$I->executeCommand('generate:suite invalid-dash-suite');
When I run it, it says it failed. However, I want it to pass because I'm deliberately adding the dash to verify it catches invalid characters. What is the best way to do that? I'm wary of a try/catch block in these tests. I'm not sure if that is the best way to do that.
After looking at the other Codeception tests, I found this to be a better way than throwing an exception:
if ($this->containsInvalidCharacters ($suite)) {
$output->writeln("<error>Suite name '{$suite}' contains invalid characters. ([A-Za-z0-9_]).</error>");
return;
}
So I modified the test to:
$I->expect ('suite is not created due to dashes');
$I->executeCommand('generate:suite invalid-dash-suite');
$I->seeInShellOutput('contains invalid characters');

Coldfusion ORM EntityToQuery NullPointerException

I am getting an error:
java.lang.NullPointerException
When I call:
<cfdump var="#posts#" top="2">
<cfset postsQuery = EntityToQuery(posts)>
dumping posts shows an array of objects as it should but for some reason the EntityToQuery(posts) is breaking. The error message is not one of the normal ones which tell you what line it broke on etc. its just the following struct:
message: [empty string]
StackTrace: java.lang.NullPointerException
TagContext: array[empty]
Type: java.lang.NullPointerException
Does anyone have any idea what could cause this? I think its data related but I don't know what to look for. Its only happening on one implementation of this code, not the others im working on.
Strange errors stopped the next time the coldfusion service was restarted.
So if anyone else has that problem.... give restarting cf a try