How does one solve this TypeDoesNotContainType error? - psalm-php

This my code:
$sftp = ssh2_sftp($connection);
if ($sftp === false) {
This is the psalm error:
ERROR: TypeDoesNotContainType - src/MyFile.php:159:13 - resource does not contain false
if ($sftp === false) {
..but the php manual says ssh2_sftp can return false:
This method returns an SSH2 SFTP resource for use with all other
ssh2_sftp_*() methods and the ssh2.sftp:// fopen wrapper, or FALSE on
failure.
What am I missing here, or what am I not understanding?

That's a bug, you need to report it to Psalm developers here: https://github.com/vimeo/psalm/issues

Related

Malformed json string perl, youtube api key

i am getting an error which i can't find the solution for .. i've spent hours on it and didn't find any fix yet. Maybe, you could help me out ? It's in perl and this is the code I am using.
method getMusicInformation($strMusicID) {
my $strLink = "https://www.googleapis.com/youtube/v3/videos?id=YqeW9_5kURI&key=AIzaSyBpzQDzTu7e59mxD9HxYP3MTdlCUWzuirQ&part=snippet";
my $strDetails = get($strLink);
my $arrDetails = decode_json($strDetails);
while (my($key, $value) = each(%{$arrDetails})) {
if (ref($value) eq 'ARRAY') {
while (my($second_key, $second_value) = each(#{$value})) {
return $second_value;
}
}
}
}
And there is the error i get in the console:
Error: malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before "(end of string)") at Server/Systems/Music.pm line 38.
The line 38 is:
my $arrDetails = decode_json($strDetails);
Thank you for understanding.
The problem is you're getting nothing back from get. The query is failing and you're not checking for an error. (Don't worry, it took me a while to figure this out, too). The clue is at character offset 0 meaning the start of the string.
LWP::Simple is too simple and does not support error checking. Instead, use the full blown LWP::UserAgent. Fortunately it's gotten a lot easier to use.
use LWP::UserAgent;
use Carp;
...
my $ua = LWP::UserAgent->new;
my $response = $ua->get($strLink);
if( !$response->is_success ) {
croak "Fetching $strLink failed: ".$response->status_line;
}
my $arrDetails = decode_json($response->decoded_content);
In my case, the problem is this:
Fetching https://www.googleapis.com/youtube/v3/videos?id=YqeW9_5kURI&key=AIzaSyBpzQDzTu7e59mxD9HxYP3MTdlCUWzuirQ&part=snippet failed: 501 Protocol scheme 'https' is not supported (LWP::Protocol::https not installed) at /Users/schwern/tmp/test.pl line 15.
main::getMusicInformation(10) called at /Users/schwern/tmp/test.pl line 30
So I need to install LWP::Protocol::https to have https support. You probably do, too.

Error when MySQLx tries to parse an expression (Nodejs)

I have downloaded the #mysql/xDevApi from NPM repository
#mysql/xdevapi and its version is 1.0.5
I am getting errors after trying out 2 different ways:-
collection.find("$.name == :name") .bind('name','Test')
-> Here it is giving name is undefined
collection.find(name == :name") .bind('name','Test')
->Here it is giving "Expecting '.', '(', got 'like'" error
Any idea on how to use this and which is the correct one? Or is there any other solution? I need to bind parameters.
Kindly suggest! Thank You!
This is the way suggested by the documentation provided--
var myRes = collection.find('name = :name').bind('name','Test').execute();
Reference:
http://dev.mysql.com/doc/x-devapi-userguide/en/parameter-binding.html

Is there a way to inquire if a class contains an instance variable with some known name?

When intercepting an error from MySql, it's not known beforehand what will be the contents of the error-class passed to me. So I code:
.catchError((firstError) {
sqlMessage = firstError.message;
try {
sqlError = firstError.osError;
} catch (noInstanceError){
sqlError = firstError.sqlState;
}
});
In this specific case I'd like to know whether e contains instance variable osError or sqlState, as any of them contains the specific errorcode. And more in general (to improve my knowledge) would it be possible write something like if (firstError.instanceExists(osError)) ..., and how?
This should do what you want:
import 'dart:mirrors';
...
// info about the class declaration
reflect(firstError).type.declarations.containsKey(#osError);
// info about the current instance
var m = reflect(firstError).type.instanceMembers[#osError];
var hasOsError = m != null && m.isGetter;
Günter's answer correctly shows how to use mirrors, however for your particular use case I'd recommend using an "is" check instead of mirrors. I don't know the mysql API specifically but it could look something like this:
.catchError((error) {
sqlMessage = error.message;
if (error is MySqlException) {
sqlError = error.sqlState;
} else if (error is OSError) {
sqlError = error.errorCode;
}
})
Perhaps ask James Ots, the author of sqljocky for advice.

How do we test for elements present using || operator in selenium webdriver

I am new to webdriver, need some guidance with the following
What I am looking for is:
if (Login || Password) webelement is not present then a message for elements not present will be present
Error what is displayed
The operator || is undefined for the argument type(s) org.openqa.selenium.WebElement, org.openqa.selenium.WebElement
Using Junit at my end
Do you just want:
if(Login.isDisplayed() == false || Password.isDisplayed() == false )
{
...
}
If not, look at the examples here, here, here, here.

AS3: Null object reference when attempting to check if it exists?

I have a weird problem. An Object is being passed to my function, and some parameters are optional, so naturally I would check to see if they are there, and if not, do nothing.
However, I'm getting a null reference error (#1009) when I'm just checking it. Here's the sample:
public function parseObject(params:Object) {
if (params.optionalParam)
trace("Got Optional Parameter!");
}
The error is returned on the line with the if statement. Changing it to check for null (if (params.optionalParam == null)) doesn't work either. The players seems to just give up if an object doesn't exist.
Is there any logical reason for this to happen? Or is it some weird bug that has just surfaced?
Thanks in Advance,
-Esa
If your params object is null, then you will get a null reference error when trying to access its' optionalParam property.
Try something like:
if (params == null)
{ trace("params is null!"); }
else if (params.optionalParam != null)
{ trace("Got optional parameter!"); }