How to fix failure to create function when deploying functions.pubsub.schedule - firebase

When I attempt to deploy the functions.pubsub.schedule like this on index.js:
const functions = firebase.functions;
var cronCount = 0;
exports.processPostsCron = functions.pubsub.schedule('* * * *
*').onRun(context => {
cronCount++;
console.log(`### this runs every minute. count: ${cronCount}`);
});
Error occured:
functions: failed to create function processPostsCron
HTTP Error: 400, The request has errors
How do I fix this error or am I doing it wrong?
I was referring to this https://github.com/firebase/functions-samples/blob/master/delete-unused-accounts-cron/functions/index.js
I am using firebase-admin#7.0.0 and firebase-functions#2.3.1.
Edit 1:
Debug result:
i functions: creating Node.js 8 function processPostsCron(us-central1)...
[2019-05-29T17:19:41.712Z] Trigger is: {"eventTrigger":{"resource":"projects/ticktock-d34b6/topics","eventType":"google.pubsub.topic.publish","service":"pubsub.googleapis.com"}}
[2019-05-29T17:19:41.714Z] >>> HTTP REQUEST POST https://cloudfunctions.googleapis.com/v1/projects/ticktock-d34b6/locations/us-central1/functions
sourceUploadUrl=https://storage.googleapis.com/gcf-upload-us-central1-f74bb5e4-12fb-4381-9f5a-ba9e11a921a8/2fac50ef-9d15-4390-8836-21209adfa8b4.zip?GoogleAccessId=service-1096541131355#gcf-admin-robot.iam.gserviceaccount.com&Expires=1559152179&Signature=EzcN7sYYs05vuTyVu7%2BMyJGU8viklA5VWPZRmMeASBCmlK6Xl%2BtMhL1G%2Fv4JHempDcLJ3FmvLDGPbar1iP%2BtNiApL%2B%2Fn6wjQINbF4CmpmqKnjxieBqpzkRYUD40zNMyCGbRDnkhcsps6DBpI9reiHvxdKkqYqadBPCaCn10nZwo96zaHcxZYHWg5PIo4cPLoPyOI7PTl4WYdwwt%2FzOHKlQSdyh1VuRgZqwfgy0vgDQR9HY846k0Tkg6RB6fGex8MzysUxiZ4RfPdt1i0LGd1KpY%2ByhG0OlEsMODQY3bBQ4TMh6LNbVyC2s9%2F0wJPkzAdJpnTjarf3hOgsF9908VkOg%3D%3D, name=projects/ticktock-d34b6/locations/us-central1/functions/processPostsCron, entryPoint=processPostsCron, deployment-tool=cli-firebase, deployment-scheduled=true, runtime=nodejs8, resource=projects/ticktock-d34b6/topics, eventType=google.pubsub.topic.publish, service=pubsub.googleapis.com
[2019-05-29T17:19:42.141Z] <<< HTTP RESPONSE 400 vary=X-Origin, Referer, Origin,Accept-Encoding, content-type=application/json; charset=UTF-8, date=Wed, 29 May 2019 17:19:42 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-29T17:19:42.141Z] <<< HTTP RESPONSE BODY code=400, message=The request has errors, status=INVALID_ARGUMENT, details=[#type=type.googleapis.com/google.rpc.BadRequest, fieldViolations=[field=pubsub_topic, description=Pub/Sub topic name projects/ticktock-d34b6/topics does not match the expected pattern]]
⚠ functions: failed to create function processPostsCron
HTTP Error: 400, The request has errors
Functions deploy had errors with the following functions:
processPostsCron
To try redeploying those functions, run:
firebase deploy --only functions:processPostsCron
To continue deploying other features (such as database), run:
firebase deploy --except functions
Error: Functions did not deploy properly.
Seems like the error occurs from:
fieldViolations=[field=pubsub_topic, description=Pub/Sub topic name projects/ticktock-d34b6/topics does not match the expected pattern]]

Firebase Support has given me the instruction to update CLI and it's all good after update. Here's the command:
npm install -g firebase-tools#latest
It didn't worked for me at first, I have added 'unsafe-perm' option to proceed:
npm install -g firebase-tools#latest --unsafe-perm

Related

How to host flutter application in Firebase?

What is the freshest instruction on how to host a flutter web app?
I am following https://developer.school/tutorials/hosting-a-flutter-web-project-on-firebase-hosting on Windows, and the step firebase init here fails for me.
Here is the content of firebase-debug.log:
You're about to initialize a Firebase project in this directory:
C:\Coding Repository\230102 flutter hello world\flutter_hello_world
Before we get started, keep in mind:
* You are currently outside your home directory
[info]
=== Project Setup
[info]
[info] First, let's associate this project directory with a Firebase project.
[info] You can create multiple project aliases by running firebase use --add,
[info] but for now we'll just set up a default project.
[info]
[info] i If you want to create a project in a Google Cloud organization or folder, please use "firebase projects:create" instead, and return to this command when you've created the project.
[debug] [2023-01-03T04:11:48.673Z] >>> [apiv2][query] POST https://cloudresourcemanager.googleapis.com/v1/projects [none]
[debug] [2023-01-03T04:11:48.674Z] >>> [apiv2][body] POST https://cloudresourcemanager.googleapis.com/v1/projects {"projectId":"flutter_hello_world_deployment_by_mish","name":"flutter_hello_world"}
[debug] [2023-01-03T04:11:48.832Z] <<< [apiv2][status] POST https://cloudresourcemanager.googleapis.com/v1/projects 400
[debug] [2023-01-03T04:11:48.832Z] <<< [apiv2][body] POST https://cloudresourcemanager.googleapis.com/v1/projects {"error":{"code":400,"message":"Request contains an invalid argument.","status":"INVALID_ARGUMENT","details":[{"#type":"type.googleapis.com/google.rpc.BadRequest","fieldViolations":[{"field":"project_id","description":"project_id must be at most 30 characters long"},{"field":"project_id","description":"project_id contains invalid characters"},{"field":"display_name","description":"project display name contains invalid characters"}]},{"#type":"type.googleapis.com/google.rpc.Help","links":[{"url":"https://cloud.google.com/resource-manager/reference/rest/v1/projects"}]}]}}
[debug] [2023-01-03T04:11:48.881Z] FirebaseError: HTTP Error: 400, Request contains an invalid argument.
at responseToError (C:\Users\mishc\AppData\Roaming\npm\node_modules\firebase-tools\lib\responseToError.js:49:12)
at RetryOperation._fn (C:\Users\mishc\AppData\Roaming\npm\node_modules\firebase-tools\lib\apiv2.js:288:77)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[error]
[error] Error: Failed to create project. See firebase-debug.log for more info.
The error message says:
project_id must be at most 30 characters long
So it sounds like you entered a project ID that was longer than that.

Firebase emulators fail to start with meaningless error

We've been using the emulators for a while now. Suddenly, they stopped working on the machines of two developers (but not all developers). They attempt to invoke firebase emulators:start and are then treated to the following error message: Error: An unexpected error has occurred.
We really have no idea why this is happening. We even tried redoing firebase init and emulators init. So far nothing we have tried has helped. Here is the console output for more detail:
➜ firebase git:(dev-vab) ✗ firebase emulators:start
i emulators: Starting emulators: functions, firestore, database, hosting, pubsub
⚠ functions: The following emulators are not running, calls to these services from the Functions emulator will affect production: auth
⚠ Your requested "node" version "10" doesn't match your global version "14"
i firestore: Firestore Emulator logging to firestore-debug.log
i database: Database Emulator logging to database-debug.log
i hosting: Serving hosting files from: public
✔ hosting: Local server: http://0.0.0.0:5000
i pubsub: Pub/Sub Emulator logging to pubsub-debug.log
i ui: Emulator UI logging to ui-debug.log
i functions: Watching "/Users/isaacmartin/git_repos/firebase/functions" for Cloud Functions...
✔ functions[updateUser]: firestore function initialized.
✔ functions[handleEventInviteeCreation]: http function initialized (http://0.0.0.0:5001/likemindedly-stage/us-central1/handleEventInviteeCreation).
i emulators: Shutting down emulators.
i ui: Stopping Emulator UI
⚠ Emulator UI has exited upon receiving signal: SIGINT
i functions: Stopping Functions Emulator
i hosting: Stopping Hosting Emulator
i database: Stopping Database Emulator
i firestore: Stopping Firestore Emulator
i pubsub: Stopping Pub/Sub Emulator
i hub: Stopping emulator hub
i logging: Stopping Logging Emulator
Error: An unexpected error has occurred.
Having trouble? Try again or contact support with contents of firebase-debug.log
Now, you will note that we did check the debug log and found the following, which may be related:
[debug] [2020-10-22T22:06:39.394Z] 15:06:39.394 [FirebaseWorkerPool-1-2] WARN com.firebase.core.namespace.NamespaceActorSystem - Request for ns: likemindedly-stage has incorrect domain. Current domain: 0.0.0.0, expected domain: firebaseio-staging.com
{"metadata":{"emulator":{"name":"database"},"message":"15:06:39.394 [FirebaseWorkerPool-1-2] WARN com.firebase.core.namespace.NamespaceActorSystem - Request for ns: likemindedly-stage has incorrect domain. Current domain: 0.0.0.0, expected domain: firebaseio-staging.com\n"}}
[debug] [2020-10-22T22:06:39.448Z] <<< HTTP RESPONSE 404 {"content-length":"231","content-type":"application/json; charset=utf-8","access-control-allow-origin":"*","cache-control":"no-cache"}
[debug] [2020-10-22T22:06:39.448Z] <<< HTTP RESPONSE BODY {
"correctUrl" : "https://likemindedly-stage.firebaseio-staging.com",
"error" : "Namespace likemindedly-stage lives in a different region. Please change your database URL to https://likemindedly-stage.firebaseio-staging.com"
}
It seems to be complaining that we are pointing at local emulators in our config, though, it's not clear why this would be a problem?
I also encountered this issue starting just a few hours ago. It allowed me to start the emulators as normal when I removed the hosts from my firebase.json, but I haven't figured out what exactly is causing the error or how to set the hosts properly outside of the json file.
Another way to solve this problem is to add the new firebase auth emulator to your emulator suite.

Deleting artifacts with JFrog CLI gives "200 OK", but artifacts are not deleted

I have created an AQL that gives me a number of artifacts I want to delete from Artifactory. I can run a search command with the jfrog-cli on it, and get the correct list of artifacts:
jfrog rt s --spec search-aql.json
When I try to delete the same artifacts with the same AQL, everything seems fine:
The artifacts are listed
I get a questions of whether to delete them or not.
I answer yes, and the command goes on to log the deletion of each item.
Each item seems to be returned and printed to my console, followed by this message:
[Error] Artifactory response: 200 OK
Binaries are also printed to the console, so the console output is really messy.
In the end, I get a summary:
{
"status": "failure",
"totals": {
"success": 0,
"failure": 68
}
}
[Error] Artifactory response: 200 OK
With the same user, I can delete individual artifacts using the REST API, so the user does have the necessary rights to do deletion.
I am on version 1.38.2 of the JFrog CLI and 7.2.1 of Artifactory.
Can anybody help me understand what is wrong or how to debug this problem?
Update 2020/08/06:
When setting the log level to debug as suggested by #Prostagma, I get two extra lines of logging for each artifact. Here is an example of logging for two artifacts:
[Info] [Thread 1] Deleting <path>/<artifact>.jar.sha512
[Debug] Sending HTTP DELETE request to: https://repo.enonic.com/<path>/<artifact>.jar.sha512
[Error] Artifactory response: 200 OK
<sha512 hash>
[Info] [Thread 0] Deleting <path>/<artifact>.jar
[Debug] Sending HTTP DELETE request to: https://repo.enonic.com/<path>/<artifact>.jar
[Error] Artifactory response: 200 OK
<binary contents of <artifact>.jar
More detailed answer to whomever encounter this issue in the future -
By diving into the code we can see that the CLI expects to get status 204 from Artifactory after deletion:
https://github.com/jfrog/jfrog-client-go/blob/v0.12.0/artifactory/services/delete.go#L110
In some installations, there may be a proxy that changes the response codes, for example when Artifactory returns 204, it may change the status code to 200.
Please make sure that your proxy doesn't change the status codes returned from Artifactory.

Invited owner of firebase project can't deploy cloud functions

I have a firebase project where I invited a developer as an owner. He got email and accepted the invitation. Yet he can't deploy functions to that project. He also tried with different internet connections. It's failing with the error below....
! functions: Upload Error: Server Error. read ECONNRESET
Error: Server Error. read ECONNRESET
firebase-debug.log
[debug] [2020-05-13T23:49:33.202Z] >>> HTTP REQUEST PUT https://storage.googleapis.com/gcf-upload-us-central1....
<request body omitted>
[warn] ! functions: Upload Error: Server Error. read ECONNRESET
[debug] [2020-05-13T23:49:55.186Z] Error: read ECONNRESET
at TLSWrap.onStreamRead (internal/stream_base_commons.js:111:27)
[error]
[error] Error: Server Error. read ECONNRESET
index.js file contains a simple function that was generated automatically by firebase init command.This is what index.js file contains..
const functions = require("firebase-functions");
exports.helloWorld = functions.https.onRequest((request, response) => {
response.send("Hello from Firebase!");
});
There was a problem with the google api link in my country. For some reason, these google API were blocked here.

Firebase Error: Unexpected error while deploying database rules

I am trying to deploy my angular app to firebase, I have tried all methods to init firebase, select hosting and then deploying my app on firebase from various tutorials. But I always get an error:
I don't know what's wrong .
This is how my firebase-debug.log looks
[debug] [2020-03-26T10:42:00.096Z] ----------------------------------------------------------------------
[debug] [2020-03-26T10:42:00.098Z] Command: C:\Program Files\nodejs\node.exe C:\Users\pulki\AppData\Roaming\npm\node_modules\firebase-tools\lib\bin\firebase.js deploy
[debug] [2020-03-26T10:42:00.098Z] CLI Version: 7.16.1
[debug] [2020-03-26T10:42:00.098Z] Platform: win32
[debug] [2020-03-26T10:42:00.098Z] Node Version: v10.16.3
[debug] [2020-03-26T10:42:00.099Z] Time: Thu Mar 26 2020 16:12:00 GMT+0530 (India Standard Time)
[debug] [2020-03-26T10:42:00.099Z] ----------------------------------------------------------------------
[debug] [2020-03-26T10:42:00.099Z]
[debug] [2020-03-26T10:42:00.105Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[debug] [2020-03-26T10:42:00.105Z] > authorizing via signed-in user
[debug] [2020-03-26T10:42:00.105Z] [iam] checking project frezzo-pul5 for permissions ["firebase.projects.get","firebasedatabase.instances.update","firebasehosting.sites.update"]
[debug] [2020-03-26T10:42:00.108Z] > refreshing access token with scopes: ["email","https://www.googleapis.com/auth/cloud-platform","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","openid"]
[debug] [2020-03-26T10:42:00.108Z] >>> HTTP REQUEST POST https://www.googleapis.com/oauth2/v3/token
<request body omitted>
[debug] [2020-03-26T10:42:00.624Z] <<< HTTP RESPONSE 200
[debug] [2020-03-26T10:42:00.630Z] >>> HTTP REQUEST POST https://cloudresourcemanager.googleapis.com/v1/projects/frezzo-pul5:testIamPermissions
[debug] [2020-03-26T10:42:02.770Z] <<< HTTP RESPONSE 200
[debug] [2020-03-26T10:42:02.772Z] >>> HTTP REQUEST GET https://firebase.googleapis.com/v1beta1/projects/frezzo-pul5
[debug] [2020-03-26T10:42:03.760Z] <<< HTTP RESPONSE 200
[info]
[info] === Deploying to 'frezzo-pul5'...
[info]
[info] i deploying database, hosting
[info] i database: checking rules syntax...
[debug] [2020-03-26T10:42:03.764Z] >>> HTTP REQUEST PUT https://frezzo-pul5.firebaseio.com/.settings/rules.json?dryRun=true
{
"rules": {
".read": true,
".write": true
}
}
[debug] [2020-03-26T10:42:06.330Z] <<< HTTP RESPONSE 404
[debug] [2020-03-26T10:42:06.330Z] <<< HTTP RESPONSE BODY {
"error" : "Firebase error. Please ensure that you spelled the name of your Firebase correctly"
}
[error]
[error] Error: Unexpected error while deploying database rules.
I have set no security on my firebase Database. Is that an issue ?
I have also tried firebase serve to locally check my app and that just works fine.
Thanks for you help !!
If you deactivated one or more of the functions since activation, when running
$ firebase init for the first time, it will mess up things when trying to deploy.
For example, sometimes realtime databases get automatically deactivated if you are not using them, just try to re-enable them to be able to deploy. Otherwise, you'll need to re-run the init with different options, and remove unused files for it to work.
Try initiating the firebase database from console. In most cases, the firebase database is not set on the cloud, so the console utility is not able to upload the db rules, and hence gives this error. Try using the following commands:
firebase init database
following updates will follow on the console:
=== Database Setup
i database: ensuring required API firebasedatabase.googleapis.com is enabled...
⚠ database: missing required API firebasedatabase.googleapis.com. Enabling now...
✔ database: required API firebasedatabase.googleapis.com is enabled
? It seems like you haven’t initialized Realtime Database in your project yet. Do you want to set it up? Yes
? Please choose the location for your default Realtime Database instance: us-central1
✔ Creating your default Realtime Database instance: ********-default-rtdb
With this, your database deployment error might get resolved.

Resources