New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong "Recipient of the message is not set." error #441
Comments
try {
$messaging->send($message);
} catch (\Exception $e) {
//Catched some wrong exception
} You're catching the exception but not doing anything with it. 😅 |
Just a general remark: Please catch Where is the The data array must be an array of string keys and string values, this is checked in https://github.com/kreait/firebase-php/blob/main/src/Firebase/Messaging/MessageData.php#L21 - so I would normally assume that the error is thrown outside of the You can configure Debug Logging for the HTTP requests/responses the SDK is sending/receiving (https://firebase-php.readthedocs.io/en/5.5.0/setup.html#logging) - this way you could check if the error message is coming from the Firebase API and what actual data has been sent to the APIs. |
Not really, that is a sample code to replicate the issue and that is why I named it wrong exception since that is the problem I faced. |
Ok.
If you run this sample code you can see the error thrown $file = 'firebaseinfo.json';
$firebase = (new Factory)->withServiceAccount($file);
$messaging = $firebase->createMessaging();
$message = CloudMessage
::withTarget('token', 'useAValidTokenHere')
->withData([
'binaryData'=>openssl_random_pseudo_bytes(5, true)
]);
$messaging->send($message); But if you run this sample code you can send the message successfully $file = 'firebaseinfo.json';
$firebase = (new Factory)->withServiceAccount($file);
$messaging = $firebase->createMessaging();
$message = CloudMessage
::withTarget('token', 'useAValidTokenHere')
->withData([
'binaryData'=>bin2hex(openssl_random_pseudo_bytes(5, true))
]);
$messaging->send($message);
Is unrelated because the "Recipient of the message" was actually set so there is no reason for that error to be thrown
My intention was never to pass binary data, I forgot to convert the binary data to string before passing it. The error received sent me looking for the issue in the wrong place. Not really critical but having a correct exception can help trace the issue. |
Thank you for the further explanations 🤗, I will try to reproduce it and find a way to catch this earlier 🤞 |
d21925a adds a simple check for binary data that doesn't catch all cases, but probably the problematic ones. Thanks again! 🙏 |
Thank you!! |
Describe the bug
When sending a message the wrong error is thrown "Recipient of the message is not set." when in fact the issue is the data passed
To Reproduce
Expected behavior
A proper error message or at least some generic message other than a completely unrelated error.
Environment
OS: Ubuntu 18.04.4 LTS (GNU/Linux 4.15.0-106-generic x86_64)
PHP version: PHP 7.2.24-0ubuntu0.18.04.6 (cli) (built: May 26 2020 13:09:11) ( NTS )
Firebase SDK Version: 5.5.0
https://www.php.net/manual/en/function.bin2hex.php
The text was updated successfully, but these errors were encountered: