Skip to content
This repository was archived by the owner on Mar 17, 2020. It is now read-only.

Commit a7d63b3

Browse files
author
Ace Nassri
authored
Add try-except example to error reporting (GoogleCloudPlatform#1659)
* Update main.py * Add Stackdriver error reporting instructions Change-Id: I8fe091456bad352936d43a7174059c7b3a35721f * Include error reporting in requirements.txt Change-Id: I3bace7962c92440d6ac3ac0169ef5ad52e06072b * Fix typo Change-Id: I42113c49d165d0b04b2ff401b236b3347913c8c8
1 parent fb7bdb5 commit a7d63b3

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

functions/helloworld/main.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,17 @@ def hello_method(request):
149149

150150
def hello_error_1(request):
151151
# [START functions_helloworld_error]
152+
# This WILL be reported to Stackdriver Error
153+
# Reporting, and WILL NOT show up in logs or
154+
# terminate the function.
155+
from google.cloud import error_reporting
156+
client = error_reporting.Client()
157+
158+
try:
159+
raise RuntimeError('I failed you')
160+
except RuntimeError:
161+
client.report_exception()
162+
152163
# This WILL be reported to Stackdriver Error Reporting,
153164
# and WILL terminate the function
154165
raise RuntimeError('I failed you')

functions/helloworld/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
google-cloud-error-reporting==0.30.0

0 commit comments

Comments
 (0)