cloud-functions-emulator icon indicating copy to clipboard operation
cloud-functions-emulator copied to clipboard

Unexpected InvalidArgumentError

Open donmccurdy opened this issue 8 years ago • 6 comments

Given a small HTTP function:

// function.js

/**
 * @param {Object} req Cloud Function request context.
 * @param {Object} res Cloud Function response context.
 */
exports.hexPrecipHttp = function hexPrecipHttp(req, res) {
  // ...
}
npm install -save-dev @google-cloud/functions-emulator
npx functions start
npx functions deploy hexPrecipHttp --trigger-http

Result:

ERROR: InvalidArgumentError: Invalid value 'hexPrecipHttp': Function name must contain only Latin letters, digits and a hyphen (-). It must start with letter, must not end with a hyphen, and must be at most 63 characters long.
    at new CloudFunction (/Users/donmccurdy/.nvm/versions/node/v6.11.3/lib/node_modules/@google-cloud/functions-emulator/src/model/cloudfunction.js:101:19)
    at Promise (/Users/donmccurdy/.nvm/versions/node/v6.11.3/lib/node_modules/@google-cloud/functions-emulator/src/cli/controller.js:309:29)
    at Controller._create (/Users/donmccurdy/.nvm/versions/node/v6.11.3/lib/node_modules/@google-cloud/functions-emulator/src/cli/controller.js:308:12)
    at client.getFunction.then (/Users/donmccurdy/.nvm/versions/node/v6.11.3/lib/node_modules/@google-cloud/functions-emulator/src/cli/controller.js:404:25)
    at process._tickCallback (internal/process/next_tick.js:109:7)

Node.js v6.11.3, npm 5.4.0.

My JS file is named function.js, and marked as main in package.json. Anything I'm missing here? The function name seems to meet all requirements listed in the error message.

donmccurdy avatar Sep 06 '17 00:09 donmccurdy

@jmdobry @laurenzlong

I am having this exact issue via firebase functions, experimental shell emulator.

And I figured out why... my project name (internal google project) contains a . and a : google.com:myproject

node v6.11.5 npm 3.10.10 firebase-admin 5.8.2 firebase-functions 0.8.1 firebase-tools 3.17.6 (installed ala: npm uninstall firebase-tools -g && npm install -g firebase-tools

It fails (see below) as follows with an error message indicating a bogus short name violation because the regexp in cloudfunction.js does not expect any non-alpha chars other than a dash.

A fix here would just involve changing the first match group to ([-:\.\w]+) and then the emulator does initialize properly.

Also need similar regexp tweak in supervisor.js in order to invoke the initialized function(s).

Here are some screenshots of the fixes in the code... emulator-patch1 emulator-patch2

Hope this helps someone.

$ firebase --debug experimental:functions:shell
[2018-03-11T00:42:09.764Z] ----------------------------------------------------------------------
[2018-03-11T00:42:09.768Z] Command:       /Users/***/.nvm/versions/node/v6.11.5/bin/node /Users/***/.nvm/versions/node/v6.11.5/bin/firebase --debug experimental:functions:shell
[2018-03-11T00:42:09.768Z] CLI Version:   3.17.6
[2018-03-11T00:42:09.768Z] Platform:      darwin
[2018-03-11T00:42:09.769Z] Node Version:  v6.11.5
[2018-03-11T00:42:09.770Z] Time:          Sat Mar 10 2018 16:42:09 GMT-0800 (PST)
[2018-03-11T00:42:09.770Z] ----------------------------------------------------------------------

[2018-03-11T00:42:09.786Z] > 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"]
[2018-03-11T00:42:09.788Z] > authorizing via signed-in user
[2018-03-11T00:42:09.792Z] >>> HTTP REQUEST GET https://admin.firebase.com/v1/projects/***

 Sat Mar 10 2018 16:42:09 GMT-0800 (PST)
[2018-03-11T00:42:11.191Z] <<< HTTP RESPONSE 200 server=nginx, date=Sun, 11 Mar 2018 00:42:11 GMT, content-type=application/json; charset=utf-8, content-length=154, connection=close, x-content-type-options=nosniff, strict-transport-security=max-age=31536000; includeSubdomains, cache-control=no-cache, no-store
[2018-03-11T00:42:11.192Z] >>> HTTP REQUEST GET https://admin.firebase.com/v1/database/***

 Sat Mar 10 2018 16:42:11 GMT-0800 (PST)
[2018-03-11T00:42:11.660Z] <<< HTTP RESPONSE 200 server=nginx, date=Sun, 11 Mar 2018 00:42:11 GMT, content-type=application/json; charset=utf-8, content-length=262, connection=close, x-content-type-options=nosniff, strict-transport-security=max-age=31536000; includeSubdomains, cache-control=no-cache, no-store
i  functions: Preparing to emulate functions.
[2018-03-11T00:42:12.425Z] Fetching environment
[2018-03-11T00:42:12.427Z] >>> HTTP REQUEST GET https://cloudresourcemanager.googleapis.com/v1/projects/***

 Sat Mar 10 2018 16:42:12 GMT-0800 (PST)
[2018-03-11T00:42:12.817Z] <<< HTTP RESPONSE 200 content-type=application/json; charset=UTF-8, vary=X-Origin, Referer, Origin,Accept-Encoding, date=Sun, 11 Mar 2018 00:42:12 GMT, server=ESF, cache-control=private, x-xss-protection=1; mode=block, x-frame-options=SAMEORIGIN, x-content-type-options=nosniff, alt-svc=hq=":443"; ma=2592000; quic=51303431; quic=51303339; quic=51303335,quic=":443"; ma=2592000; v="41,39,35", accept-ranges=none, connection=close
[2018-03-11T00:42:12.818Z] >>> HTTP REQUEST GET https://mobilesdk-pa.googleapis.com/v1/projects/***:getServerAppConfig

 Sat Mar 10 2018 16:42:12 GMT-0800 (PST)
[2018-03-11T00:42:13.488Z] <<< HTTP RESPONSE 200 content-type=application/json; charset=UTF-8, vary=X-Origin, Referer, Origin,Accept-Encoding, date=Sun, 11 Mar 2018 00:42:13 GMT, server=ESF, cache-control=private, x-xss-protection=1; mode=block, x-frame-options=SAMEORIGIN, x-content-type-options=nosniff, alt-svc=hq=":443"; ma=2592000; quic=51303431; quic=51303339; quic=51303335,quic=":443"; ma=2592000; v="41,39,35", accept-ranges=none, connection=close
[2018-03-11T00:42:13.489Z] Starting @google-cloud/functions-emulator
[2018-03-11T00:42:15.049Z] Parsing function triggers
[2018-03-11T00:42:15.331Z] Deploying functions locally
[2018-03-11T00:42:15.370Z] Error while deploy to emulator: InvalidArgumentError: Invalid value 'makeUppercase': Function name must contain only Latin letters, digits and a hyphen (-). It must start with letter, must not end with a hyphen, and must be at most 63 characters long.
    at new CloudFunction (/Users/***/.nvm/versions/node/v6.11.5/lib/node_modules/firebase-tools/node_modules/@google-cloud/functions-emulator/src/model/cloudfunction.js:106:19)
    at Promise (/Users/***/.nvm/versions/node/v6.11.5/lib/node_modules/firebase-tools/node_modules/@google-cloud/functions-emulator/src/cli/controller.js:284:29)
    at Controller._create (/Users/***/.nvm/versions/node/v6.11.5/lib/node_modules/firebase-tools/node_modules/@google-cloud/functions-emulator/src/cli/controller.js:283:12)
    at client.getFunction.then (/Users/***/.nvm/versions/node/v6.11.5/lib/node_modules/firebase-tools/node_modules/@google-cloud/functions-emulator/src/cli/controller.js:392:25)
    at process._tickDomainCallback (internal/process/next_tick.js:135:7)
⚠  functions: Failed to emulate makeUppercase
No functions emulated.

louggl avatar Mar 11 '18 01:03 louggl

I can confirm that @louggl 's solution works. I had the same problem with a Google internal firebase project.

Also, make sure to edit the correct file and to restart the emulator. Running firebase serve --debug (see above) should log the correct path to the emulator directory (most probably in the firebase-tools dir, not in the @ google-cloud dir).

djaax avatar Sep 11 '18 09:09 djaax

i am facing the same issue. functions-emulator deploy helloWorld --trigger-http ERROR: InvalidArgumentError: Invalid value 'helloWorld': Function name must contain only Latin letters, digits and a hyphen (-). It must start with letter, must not end with a hyphen, and must be at most 63 characters long. at new CloudFunction (/Users/user/.nvm/versions/node/v6.14.4/lib/node_modules/@google-cloud/functions-emulator/src/model/cloudfunction.js:106:19) at Promise (/Users/user/.nvm/versions/node/v6.14.4/lib/node_modules/@google-cloud/functions-emulator/src/cli/controller.js:284:29) at Controller._create (/Users/user/.nvm/versions/node/v6.14.4/lib/node_modules/@google-cloud/functions-emulator/src/cli/controller.js:283:12) at client.getFunction.then (/Users/user/.nvm/versions/node/v6.14.4/lib/node_modules/@google-cloud/functions-emulator/src/cli/controller.js:392:25) at process._tickCallback (internal/process/next_tick.js:109:7)

Sandeeprao69 avatar Oct 25 '18 07:10 Sandeeprao69

@Sandeeprao69 did you resolve your issue?

derek-baker avatar Jan 02 '19 02:01 derek-baker

Hey @derek-baker, Yes i was able to resolve this issue. I was using nvm with multiple node versions and function-emulator was installed on two diff node versions.

Sandeeprao69 avatar Jan 02 '19 03:01 Sandeeprao69

Hi, I had same issue. I followed @louggl solution and I'm able to emulate (serve) functions locally. But since my ID has colon in name I see troubles deploying it to Firebase. Were you, guys, able to deploy your code in case your projectId had colons/comma in name?

dominikbulaj avatar Mar 19 '19 12:03 dominikbulaj