firebase-functions:
"1.1.0"
firebase-tools:
"3.19.3"
firebase-admin:
"5.12.1"
Create a firestore trigger like so:
export const addData = functions.firestore.document('users').onCreate((snap, context) => {
const newUser = snap.id
return snap.ref.set({
'nickname': 'usernickname'
}, { merge: true})
})
When you deploy this function, you get the following error message:
failed to create function <functionName>AddData
HTTP Error: 400, The request has errors
What went wrong is not clear. After googling, I stumbled on this StackOverflow bit: https://stackoverflow.com/questions/46818082/error-http-error-400-the-request-has-errors-firebase-firestore-cloud-function.
No, see the reproduce steps above
It should give me an error message that is helpful and identifies that the document path is invalid.
The error message is vague and doesn't tell the user that the document path is invalid:
failed to create function <functionName>AddData
HTTP Error: 400, The request has errors
Thanks for filing! We are aware of this issue and are working on it.
Internal bug reference: 111570647
You should use a wildcard after the collection, like this:
export const addData = functions.firestore.document('users/{userId}').onCreate((snap, context) => {
const newUser = snap.id
return snap.ref.set({
'nickname': 'usernickname'
}, { merge: true})
})
any solution to this issue?
I have the same problem
@ahadortiz We are working out the best way to propagate the error to the user - error propagation is an issue that is not limited to the Firestore module but rather the whole Functions SDK, so it will take time to implement consistently across the codebase. Thank you for your patience!
Quick update - since this is a wider issue that involves not just the functions SDK but also the Google Cloud Functions and how it propagates errors from the event sources, it merits further discussion internally to understand the best way to go about this. Additionally, our team is quite under resourced, so we likely won't be getting to this soon.
We generally keep issues isolated to the functions SDK open on Github, and since this is not the case here, I'm going to close this out. Please know that I will still post updates here if there is progress on the internal bugs (we link to this thread in the bugs). Thanks for everyone's patience!
Is there a reason you haven't documented this behavior? If the Firestore documentation had even _once_ mentioned that trailing slashes are not permitted, it could have saved me hours of confusion.
Updating the original example to illustrate that even trailing slashes cause this problem:
export const addData = functions.firestore.document('users/{uid}/').onCreate((a, c) => {})
I think any developer could reasonably expect a trailing slash to work, therefore I recommend the docs at least mention this limitation:
Note: Cloud Firestore events are triggered at Collection and Document level only. It is not possible to add events to specific fields – even adding a trailing slash ('collection/document/') will cause an error at deployment time.
Just saying. It's been 2 years and I just stumbled across this issue because
my observer on firestore had an invalid path and all I got as an error when deploying was:
HTTP Error: 400, The request has errors
@cdstamper Thanks for the idea of documenting this behavior, I'll file a bug for our tech writing team to look into documenting this more clearly. (Internal bug reference 149922654). As @thechenky mentioned, ensuring that the error message is more helpful is unfortunately difficult to do at this time, but we can at least document it better.
Most helpful comment
Just saying. It's been 2 years and I just stumbled across this issue because
my observer on firestore had an invalid path and all I got as an error when deploying was:
HTTP Error: 400, The request has errors