Hi.
It seem that we cannot handle exception.
I tried with the three following snippets
try {
const ref = firebase.database().ref(type).push();
let newRef = await ref.set(properties);
console.log(`----> (OK) <----`, newRef);
} catch(err) {
console.log(`----> (ERROR) <----`, err);
}
``javascript
const ref = firebase.database().ref(type).push();
await ref.set(properties, (err, res) => {
if(err) {
console.log(----> (ERROR) <----, err);
return;
}
console.log(----> (OK) <----`, res);
});
```javascript
const ref = firebase.database().ref(type).push();
await ref.set(properties).then(newRef => {
console.log(`----> (OK) <----`, newRef)
}).catch(error => console.log(`----> (ERROR) <----`, error))
no message from my code was displayed in console, only this:
Exception '(setValue:withCompletionBlock:) Invalid key in object at path: . Keys must be non-empty and cannot contain '/' '.' '#' '$' '[' or ']'' was thrown while invoking set on target RNFirebaseDatabase with params (
"xxxx/-Kq-Clu4YMgjXkilJoX7",
{
type = object;
value = {
"$test" = ciao;
"_key" = a;
"_uptodate" = 1;
};
},
949
)

Looks like this is another case of the iOS firebase SDk not sending errors into the completion block but rather throw the error outside of it, urghhh.
That's the line on iOS code that's throwing the error I imagine, should be going inside the completion block on line 147, could you try debug break on line 147 and see if it gets inside the block for me?
Hi @Salakar,
Unfortunately I can't help you to debug because I don't know ios code, maybe someone else who knows the native code can give you this info
@bitlab-code just open the file/line in Xcode and put a debugger mark on the line. When your app runs it will stop running on that line and show you the value of the error.
Not sure what the best way to approach this is, there's two options:
1) Add js side validation of keys - but it's not just invalid keys that could cause an issue
2) Try/Catch statements around each native method on ios, which is just meh. Though may be the best solution as i believe auth has the same issues, the firebase native sdk basically doesn't go into the onFailure listeners correctly - it randomly throws an error outside - has been flagged with them but I guess it's just one of those things we have to work around.
Will see what I can come up with for v3.
@Salakar Try/Catch statements around each native method to throw a JS relative exception, look like the right way.
Thanks for watching this.
Thanks @Salakar for quick response. This there any ETA for this? This is pretty critical since any error from firebase will crash the app (eg, wrong username/password). We want to use this in a production app in next 2 weeks but this turned out to be a blocker.
@amitava82 it's not any error, it's only errors that are client sided, i.e you give an empty string as an email address, or an invalid string as a path, as above. All other errors like wrong password etc are server sided, which means they'll go through the current logic just fine and reject the promise correctly.
It's more of a case of validate your input :) however we're gonna add something in for this so the errors are routed through the promises
All other errors like wrong password etc are server sided, which means they'll go through the current logic just fine and reject the promise.
This seems to be not the case. I entered an invalid username & password and the application did not catch error returned from server.
Could you define invalid? @amitava82
wrong email/password.
If valid credentials are [email protected]/password and try to login with [email protected]/pass the server will throw error that is not being caught in catch block.
Looks like we need to 'try catch' these natively. We'' get this done for a future release
not sure if it's directly related to this issue, but it seems that multi-path updates are affected by this.
in my case ref().set('parent/child', value) works fine while ref().update({ 'parent/child': value }) throws the aforementioned error.
(Android, @3.1.0)
This issue has been automatically marked as stale because it has not had recent user activity. It will be closed if no further activity occurs. Thank you for your contributions.
Hi
I'm with the same issue.
The problem is that I used to save FCM token in firebase database, using token as key of object for like a unique key guarantee.
But, suddely, I got a FCM token that contained these invalid characteres, so we have to save our FCM token as a object value. Now I'm using userId of firebase Auth API for unique key. But I'm not sure wheter userId contains these invalid chars too.
So I would like to handle this error to know if that occours with userId too. I think no, but who knows?
Using firebase Admin SDK with a nodeJs script, I can catch this error easily.
With react native, I trying:
try {
await firebaseReactNative.database().ref("someRefWith#").once("value")
} catch (error) {
console.log(error);
}
It occours with set, once('value'), and other methods too.
Environment
Target Platform: Android/IOS
Development Operating System: macOS HighSierra
React Native version 0.53.3
RNFirebase Version 4.3.8
All this is being addressed in the upcoming v6 release. Due to the size of the internal changes required to solve this, it's best it's done on a major release.
You can learn more about this release and other upcoming Open Source here: https://blog.invertase.io/react-native-firebase-2019-7e334ca9bcc6
This has now been handled in v6 with many additional JS side validations added to prevent this + trapping all native errors and rejecting back to JS.
It still happens in android (IOS works ok) when calling signInWithEmailAndPassword exceptions are not thrown to be handled in then catch block instead get an error screen.
I'm using the latest release:
"@react-native-firebase/app": "^6.3.4",
"@react-native-firebase/auth": "^6.3.4",

@andresd - this is a closed issue, and about database. Perhaps open a new issue or (even better) this one is probably pretty easy to fix as a PR