Firebase Cloud Functions 「HTTP Error: 400, The request has errors」でよくあるミス


Cloud Functionsのエラー

エラーメッセージに含まれてる情報があまりにも少ない。。。

HTTP Error: 400, The request has errors


Functions deploy had errors with the following functions:
    myFuction


To try redeploying those functions, run:
    firebase deploy --only functions: myFuction


To continue deploying other features (such as database), run:
    firebase deploy --except functions

Error: Functions did not deploy properly.

404エラーの原因は何よ?ってことで、結構手こずった。。が、タイプミス並みの凡ミスでした。。

原因

ダメなパターン

index.ts
exports.myFuction = functions.firestore
  .document('users/{userId}/events')
  .onWrite((change, context) => {
    // 略
  });

OKなパターン

index.ts
exports.myFuction = functions.firestore
  .document('users/{userId}/events/{eventId}')
  .onWrite((change, context) => {
    // 略
  });

documentを参照しなければいけないところでcollectionのパスを指定していたので、エラーを突きつけられたようだ。