12

I tried Google Cloud Functions with Python and there was a problem with running it. It said: Error: could not handle the request

I checked the logs, but there was no error, just a log message:

Function execution took 16 ms, finished with status: 'crash'

When I simplified the function to a printout then it worked properly. Then I added raise Exception('test') before the printout to see if the exception is going to Stackdriver Errors, but it didn't, I got the finished with status: 'crash' message again only in the log.

Is this normal behavior? Or is it a bug and instead of crash I should see the exception as an error in the log?

Tom
  • 7,515
  • 7
  • 38
  • 54
  • 3
    My experience is also that we see a "crash" record with no further details. My belief is that you are supplying a function in Python and if that function throws an exception, it is caught higher up the stack and recorded as a crash. If you want to see the exception, place a try / except bracketing your code in the function. Then if an exception is thrown, you will catch it and can log it yourself (if your choose) and then re-throw the exception. – Kolban May 24 '20 at 15:50
  • Catching everything is a workaround, thanks, though according to the docs it shouldn't be necessary, so it must be a bug: "Uncaught exceptions produced by your function will appear in Stackdriver Error Reporting. " https://cloud.google.com/functions/docs/monitoring/error-reporting – Tom May 24 '20 at 16:00
  • 1
    You have raised a GREAT question. I tried with both JavaScript and Python. With JavaScript, we get a trace in the log and an Error Report is created. With Python, all we get is a "finished with crash" and no details in the log and no Error Report ... quest continues. – Kolban May 24 '20 at 18:45
  • 1
    See also: https://stackoverflow.com/questions/61990583/gcp-cloud-functions-no-longer-categorizes-errors-correctly-with-tracebacks – Kolban May 24 '20 at 19:08
  • Did you solve this problem @Tom? – Knowledge Seeker Jul 24 '20 at 16:02

3 Answers3

5

Quite rightly, as alluded to in the Comments, the crash seems buggy about Google Cloud Functions with Python. The issue was reported to the Internal Google Cloud Functions engineers and evaluation is still ongoing. You can monitor this link for fixes

oakinlaja
  • 826
  • 6
  • 10
  • 1
    More recent issue: https://issuetracker.google.com/issues/155215191 – Emre Jul 20 '20 at 20:26
  • Is this bug applicable for golang as well? I am running into the same scenario. – dhamu Nov 05 '20 at 22:43
  • Unfortunately, no! The Bug is specific to the issue on Python runtime. I think you should open a new [issue link](https://developers.google.com/issue-tracker/#public_users) for further review on the issue you are experiencing. – oakinlaja Nov 06 '20 at 14:17
1
def wrapper(request):
    try:
        your_main_gcf(request)
    except Exception as e:
        print(e)

Also, mark 'wrapper' as function to execute in settings for GCF

Iurii Aleev
  • 81
  • 1
  • 4
1

In my case, I was using code like this:

await Promise.all([
   Promise1,
   Promise2,
   Promise3
]);

Here Promise2 is uploading a file in google bucket but I mistakenly have put dev-gcp.json in .gitignore which ignoring dev-gcp.json(google application credential) on deploying function. This makes an error on google bucket storage when it not able to find dev-gcp.json for authentication. So make sure whatever in the promise is handled properly because some errors are not expected and are not handled.