2
votes

I'm running into a strange issue.

I'm trying to use 2 wildcards and I keep getting an error saying:

! functions: failed to create function modRemoveReplies

HTTP Error: 400, The request has errors

The interesting thing is that I have another export that uses almost the same wildcards but doesn't produce an error...

This is the code where I get an error:

exports.modRemoveReplies = functions.database
  .ref('replies/{parent}/{postId}/flag_delete')
  .onCreate(async (snapshot, context) => {
    console.log("Test")
    return true;
});

but earlier in my functions file I call this code with absolute no errors:

exports.removeReply = functions.database
  .ref('replies/{parent}/{postId}/score')
  .onUpdate(async change => {
    const score = change.after.val();
    if (score === -4) {
      return change.after.ref.parent.remove();
    }
  });

It's practically identical so I understand why 'd be getting that error... Any ideas? The error message above is the only information that gets displayed.

Edit:

After running with the --debug flag this was the output:

[2019-05-30T20:55:47.156Z] <<< HTTP RESPONSE 400 vary=X-Origin, Referer, Origin,Accept-Encoding, content-type=application/json; charset=UTF-8, date=Thu, 30 May 2019 20:55:43 GMT, server=ESF, cache-control=private, x-xss-protection=0, x-frame-options=SAMEORIGIN, x-content-type-options=nosniff, alt-svc=quic=":443"; ma=2592000; v="46,44,43,39", accept-ranges=none, connection=close

[2019-05-30T20:55:47.156Z] <<< HTTP RESPONSE BODY code=400, message=The request has errors, status=INVALID_ARGUMENT, details=[@type=type.googleapis.com/google.rpc.BadRequest, fieldViolations=[field=runtime, description=Runtime field cannot be empty.]]

2
Run the command with --debug and edit the question to show what it's saying. If the output isn't helpful, you might have to contact Firebase support.Doug Stevenson
@DougStevenson Thanks, I edited the question to include the information from the --debug flagSimon
Make sure your CLI is fully up to date, try again, and contact Firebase support directly if you still have problems. support.google.com/firebase/contact/supportDoug Stevenson
@DougStevenson Thanks, I figured it out and answered my own question :)Simon
For me running "npm install -g firebase-tools" solved the problemyital9

2 Answers

3
votes

In my case I had to change

export const onRatingCreated = functions.firestore.document('Programs/{programId}/Ratings/').onCreate((doc, context) => {
    // ...
});

To this

export const onRatingCreated = functions.firestore.document('Programs/{programId}/Ratings/{ratingId}').onCreate((doc, context) => {
    // ...
});

So, ending with a Document wildcard fixed it for me.

2
votes

I experienced this issue because my path was incorrect. I had it like this:

functions.firestore
.document('/companies/{companyID}/tickets/')
  .onCreate((change, context) => { 

  // code here.

  })

Instead of:

functions.firestore
.document('/companies/{companyID}/tickets')
  .onCreate((change, context) => { 

  // code here.

  })

Note the slash at the end of the path.