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

Can't determine the issue based on error output

Open atrauzzi opened this issue 7 years ago • 10 comments

I'm running the emulator and my code seems to be running successfully, all the way up to the point of getting a Buffer and assigning it as a reply.

The code that sends things back is found here. In my testing, I'm definitely able to get up to this point, but even if I put a plain string message in there, I still get this same error:

{
    "error": {
        "code": 500,
        "status": "INTERNAL",
        "message": "function crashed",
        "errors": [
            "Parse Error"
        ]
    }
}

Something is getting tripped up no matter what I put in that .send callback.

While I'm okay with assuming that something in my response might be bad, the generic message of "Parse Error" really doesn't give me anything to go off of.

Any chance I can get this deciphered for me, and then beyond that, any chance of improving error output? Really if I can't get clarity when using a local emulator, I'm not inclined to target any production environment.

atrauzzi avatar Jun 18 '17 14:06 atrauzzi

Can you please provide reproduction steps with which I can reproduction steps? Without those I can't really debug this for you.

jmdobry avatar Jun 21 '17 15:06 jmdobry

Check out this repository: https://github.com/atrauzzi/protoculture-google-cloud-functions

atrauzzi avatar Jun 22 '17 13:06 atrauzzi

Quick update: It's a bit involved, but run these commands in order from the demo directory:

tsc
functions start
clear
functions deploy protoculture --trigger-http

I think to access, it's just a matter of going to: http://localhost:8010/blah/us-central1/protoculture

atrauzzi avatar Jun 25 '17 18:06 atrauzzi

I followed your steps, and I got:

ERROR: Error: Node.js module defined by file index.js is expected to export function named protoculture

After inspecting the index.js generated by the tsc command, I don't see any exported function named protoculture.

jmdobry avatar Jun 28 '17 16:06 jmdobry

Is there any way to improve the error output to indicate this? I never end up seeing that error anywhere.

Are you sure I need to name the function in my export? The cloud functions docs make it seem like so long as I export a function, it will see it?

atrauzzi avatar Jun 28 '17 18:06 atrauzzi

The Emulator expects a named function. Can you point me to the Cloud Functions docs where they make it seem like you can export just a function? If that's valid behavior then I need to update the Emulator.

As far as why you didn't see that error output, I have no idea. That's something I wasn't able to reproduce. Are you on Windows?

jmdobry avatar Jul 10 '17 17:07 jmdobry

I recommend you export a named function.

jmdobry avatar Jul 11 '17 14:07 jmdobry

Yeah, I'm on Windows.

Here's the doc: https://cloud.google.com/functions/docs/writing/

Specifically this part:

image

atrauzzi avatar Jul 11 '17 15:07 atrauzzi

I can see the confusion, it appears that "exports one or more functions" is ambiguous. I will update those docs to say "exports one or more functions via named exports".

jmdobry avatar Jul 11 '17 16:07 jmdobry

That would be awesome, thank you! :)

atrauzzi avatar Jul 11 '17 17:07 atrauzzi