You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The docs say that getFunctions().taskQueue(targetUri) should accept three formats:
A fully qualified function resource name: projects/{project}/locations/{location}/functions/{functionName}
A partial resource name with location and function name, in which case the runtime project ID is used: locations/{location}/functions/{functionName}
A partial function name, in which case the runtime project ID and the default location, us-central1, is used: {functionName}
But I have found the Cloud Tasks emulator only works with format number 3 (functionName). All the other formats throw a 404 error.
Here is the example code:
import*asadminfrom"firebase-admin";import{onRequest}from"firebase-functions/v2/https";import{getFunctions}from"firebase-admin/functions";import{onTaskDispatched}from"firebase-functions/v2/tasks";import*asloggerfrom"firebase-functions/logger";// Initialize the Firebase appadmin.initializeApp();// The task functionexportconsttestOnRequest=onRequest(async(request,response)=>{consttaskPayload={foo: "bar",};consttargetUri="testOnTaskDispatched";// <-- This works :)// const targetUri = "locations/us-central1/functions/testOnTaskDispatched"; // <-- This does NOT work :(// const targetUri =// "projects/demo-project/locations/us-central1/functions/testOnTaskDispatched"; // <-- This does NOT work :(constqueue=getFunctions().taskQueue(targetUri);try{awaitqueue.enqueue(taskPayload);}catch(error){console.error("Error scheduling task",error);response.status(500).send("Error scheduling task");return;}response.send("Hello from HTTP ON REQUEST!");});// The http functionsexportconsttestOnTaskDispatched=onTaskDispatched((request)=>{logger.info("Hello logs from TASKS ON TASK DISPATCHED!",{foo: request.data,});});
Here is the error that is thrown inside the emaultor:
Error scheduling task FirebaseFunctionsError: Unexpected response with status: 404 and body: <!DOCTYPE html>
10:55:50
I
function[us-central1-testOnRequest]
<html lang="en">
10:55:50
I
function[us-central1-testOnRequest]
<head>
10:55:50
I
function[us-central1-testOnRequest]
<meta charset="utf-8">
10:55:50
I
function[us-central1-testOnRequest]
<title>Error</title>
10:55:50
I
function[us-central1-testOnRequest]
</head>
10:55:50
I
function[us-central1-testOnRequest]
<body>
10:55:50
I
function[us-central1-testOnRequest]
<pre>Cannot POST /projects/demo-project/locations/us-central1/queues/locations/us-central1/functions/testOnTaskDispatched/tasks</pre>
10:55:50
I
function[us-central1-testOnRequest]
</body>
10:55:50
I
function[us-central1-testOnRequest]
</html>
10:55:50
I
function[us-central1-testOnRequest]
>
10:55:50
I
function[us-central1-testOnRequest]
at FunctionsApiClient.toFirebaseError (/Users/BenJackGill/Dev/fire/functions/node_modules/firebase-admin/lib/functions/functions-api-client-internal.js:313:20)
10:55:50
I
function[us-central1-testOnRequest]
at FunctionsApiClient.enqueue (/Users/BenJackGill/Dev/fire/functions/node_modules/firebase-admin/lib/functions/functions-api-client-internal.js:149:32)
10:55:50
I
function[us-central1-testOnRequest]
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
10:55:50
I
function[us-central1-testOnRequest]
at async /Users/BenJackGill/Dev/fire/functions/lib/index.js:22:9
10:55:50
I
function[us-central1-testOnRequest]
at async runFunction (/Users/BenJackGill/.nvm/versions/node/v20.11.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:506:9)
10:55:50
I
function[us-central1-testOnRequest]
at async runHTTPS (/Users/BenJackGill/.nvm/versions/node/v20.11.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:531:5)
10:55:50
I
function[us-central1-testOnRequest]
at async /Users/BenJackGill/.nvm/versions/node/v20.11.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:694:21 {
10:55:50
I
function[us-central1-testOnRequest]
errorInfo: {
10:55:50
I
function[us-central1-testOnRequest]
code: 'functions/unknown-error',
10:55:50
I
function[us-central1-testOnRequest]
message: 'Unexpected response with status: 404 and body: <!DOCTYPE html>\n' +
10:55:50
I
function[us-central1-testOnRequest]
'<html lang="en">\n' +
10:55:50
I
function[us-central1-testOnRequest]
'<head>\n' +
10:55:50
I
function[us-central1-testOnRequest]
'<meta charset="utf-8">\n' +
10:55:50
I
function[us-central1-testOnRequest]
'<title>Error</title>\n' +
10:55:50
I
function[us-central1-testOnRequest]
'</head>\n' +
10:55:50
I
function[us-central1-testOnRequest]
'<body>\n' +
10:55:50
I
function[us-central1-testOnRequest]
'<pre>Cannot POST /projects/demo-project/locations/us-central1/queues/locations/us-central1/functions/testOnTaskDispatched/tasks</pre>\n' +
10:55:50
I
function[us-central1-testOnRequest]
'</body>\n' +
10:55:50
I
function[us-central1-testOnRequest]
'</html>\n'
10:55:50
I
function[us-central1-testOnRequest]
},
10:55:50
I
function[us-central1-testOnRequest]
codePrefix: 'functions'
10:55:50
I
function[us-central1-testOnRequest]
}
Hey @BenJackGill, thanks for raising this and for creating a thorough report! This is appreciated. I’m able to reproduce the error using the mcve and steps you provided. Let me notify our engineering team about this.
[REQUIRED] Environment info
firebase-tools: 13.20.2
Platform: macOS
[REQUIRED] Test case
Trying to use the new Cloud Tasks emulator.
The docs say that
getFunctions().taskQueue(targetUri)
should accept three formats:projects/{project}/locations/{location}/functions/{functionName}
locations/{location}/functions/{functionName}
{functionName}
But I have found the Cloud Tasks emulator only works with format number 3 (
functionName
). All the other formats throw a 404 error.Here is the example code:
Here is the error that is thrown inside the emaultor:
[REQUIRED] Steps to reproduce
cd functions
npm i
npm run serve
[REQUIRED] Expected behavior
The Cloud Task emulator should run the task function without error.
[REQUIRED] Actual behavior
It produces a 404 error.
The text was updated successfully, but these errors were encountered: