From f33371c10f0eea8d1b2658a4aab55bbfac7b4919 Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Wed, 9 May 2018 14:32:10 -0700 Subject: [PATCH 1/7] Adjust retry error tags --- functions/tips/index.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/functions/tips/index.js b/functions/tips/index.js index 7616ebf844..3257852a4f 100644 --- a/functions/tips/index.js +++ b/functions/tips/index.js @@ -160,7 +160,7 @@ exports.avoidInfiniteRetries = (event, callback) => { }; // [END functions_tips_infinite_retries] -// [START functions_tips_retry_promise] +// [START functions_tips_retry] /** * Background Cloud Function that demonstrates * how to toggle retries using a promise @@ -172,15 +172,15 @@ exports.avoidInfiniteRetries = (event, callback) => { exports.retryPromise = (event) => { const tryAgain = !!event.data.retry; + // [START functions_tips_retry_promise] if (tryAgain) { throw new Error(`Retrying...`); } else { return Promise.reject(new Error('Not retrying...')); } + // [END functions_tips_retry_promise] }; -// [END functions_tips_retry_promise] -// [START functions_tips_retry_callback] /** * Background Cloud Function that demonstrates * how to toggle retries using a callback @@ -194,6 +194,7 @@ exports.retryCallback = (event, callback) => { const tryAgain = !!event.data.retry; const err = new Error('Error!'); + // [START functions_tips_retry_callback] if (tryAgain) { console.error('Retrying:', err); callback(err); @@ -201,8 +202,9 @@ exports.retryCallback = (event, callback) => { console.error('Not retrying:', err); callback(); } + // [END functions_tips_retry_callback] }; -// [END functions_tips_retry_callback] +// [END functions_tips_retry] // [START functions_tips_gcp_apis] const Pubsub = require('@google-cloud/pubsub'); From ff5f7c2be3e8df66e782d95a943fbcf820b46a66 Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Wed, 9 May 2018 16:48:21 -0700 Subject: [PATCH 2/7] Unify hello-world error region-tags --- functions/helloworld/index.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/functions/helloworld/index.js b/functions/helloworld/index.js index 32ceeb4263..21ff56fd51 100644 --- a/functions/helloworld/index.js +++ b/functions/helloworld/index.js @@ -117,13 +117,13 @@ exports.helloGCSGeneric = (event, callback) => { }; // [END functions_helloworld_storage_generic] -// [START functions_helloworld_error] /** * Background Cloud Function that throws an error. * * @param {object} event The Cloud Functions event. * @param {function} callback The callback function. */ +// [START functions_helloworld_error] exports.helloError = (event, callback) => { // This WILL be reported to Stackdriver errors throw new Error('I failed you'); @@ -131,31 +131,32 @@ exports.helloError = (event, callback) => { // [END functions_helloworld_error] /* eslint-disable */ -// [START functions_helloworld_error_2] /** * Background Cloud Function that throws a value. * * @param {object} event The Cloud Functions event. * @param {function} callback The callback function. */ +// [START functions_helloworld_error] exports.helloError2 = (event, callback) => { // This will NOT be reported to Stackdriver errors throw 1; }; -// [END functions_helloworld_error_2] +// [END functions_helloworld_error] -// [START functions_helloworld_error_3] /** * Background Cloud Function that throws an error. * * @param {object} event The Cloud Functions event. * @param {function} callback The callback function. */ +// [START functions_helloworld_error] exports.helloError3 = (event, callback) => { // This will NOT be reported to Stackdriver errors callback('I failed you'); }; -// [END functions_helloworld_error_3] +// [END functions_helloworld_error] + /* eslint-enable */ // [START functions_helloworld_template] From 061f048e85b618ed3be0815c98b2f977bbd2987b Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Wed, 9 May 2018 17:00:11 -0700 Subject: [PATCH 3/7] Further error sample unification --- functions/helloworld/index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/functions/helloworld/index.js b/functions/helloworld/index.js index 21ff56fd51..e71b494fee 100644 --- a/functions/helloworld/index.js +++ b/functions/helloworld/index.js @@ -125,9 +125,11 @@ exports.helloGCSGeneric = (event, callback) => { */ // [START functions_helloworld_error] exports.helloError = (event, callback) => { - // This WILL be reported to Stackdriver errors + // These WILL be reported to Stackdriver errors + console.error('I failed you'); throw new Error('I failed you'); }; + // [END functions_helloworld_error] /* eslint-disable */ @@ -139,8 +141,10 @@ exports.helloError = (event, callback) => { */ // [START functions_helloworld_error] exports.helloError2 = (event, callback) => { - // This will NOT be reported to Stackdriver errors - throw 1; + // These will NOT be reported to Stackdriver errors + console.info(new Error('message')); // Logging an Error object at the info level + console.error('message'); // Logging something other than an Error object + throw 1; // Throwing something other than an Error object }; // [END functions_helloworld_error] From ef1dee605ac6249746dfcc56db1a234b1650bbc8 Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Wed, 9 May 2018 17:19:34 -0700 Subject: [PATCH 4/7] Clarify comments + add HTTP sample --- functions/helloworld/index.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/functions/helloworld/index.js b/functions/helloworld/index.js index e71b494fee..fc0d09e0d0 100644 --- a/functions/helloworld/index.js +++ b/functions/helloworld/index.js @@ -127,42 +127,56 @@ exports.helloGCSGeneric = (event, callback) => { exports.helloError = (event, callback) => { // These WILL be reported to Stackdriver errors console.error('I failed you'); - throw new Error('I failed you'); + throw new Error('I failed you'); // Will cause a cold start if not caught }; // [END functions_helloworld_error] -/* eslint-disable */ /** * Background Cloud Function that throws a value. * * @param {object} event The Cloud Functions event. * @param {function} callback The callback function. */ +/* eslint-disable no-throw-literal */ // [START functions_helloworld_error] exports.helloError2 = (event, callback) => { // These will NOT be reported to Stackdriver errors - console.info(new Error('message')); // Logging an Error object at the info level - console.error('message'); // Logging something other than an Error object + console.info(new Error('I failed you')); // Logging an Error object at the info level + console.error('I failed you'); // Logging something other than an Error object throw 1; // Throwing something other than an Error object }; // [END functions_helloworld_error] +/* eslint-enable no-throw-literal */ /** - * Background Cloud Function that throws an error. + * Background Cloud Function that returns an error. * * @param {object} event The Cloud Functions event. * @param {function} callback The callback function. */ +/* eslint-disable */ // [START functions_helloworld_error] exports.helloError3 = (event, callback) => { // This will NOT be reported to Stackdriver errors callback('I failed you'); }; // [END functions_helloworld_error] - /* eslint-enable */ +/** + * HTTP Cloud Function that returns an error. + * + * @param {Object} req Cloud Function request context. + * @param {Object} res Cloud Function response context. + */ +// [START functions_helloworld_error] +exports.helloError4 = (req, res) => { + // This will NOT be reported to Stackdriver errors + res.status(500).send('I failed you'); +}; +// [END functions_helloworld_error] + // [START functions_helloworld_template] const path = require('path'); const pug = require('pug'); From 8e0e0ae73eca2c0208d2a169bf17a5ae9e61c583 Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Thu, 10 May 2018 10:07:51 -0700 Subject: [PATCH 5/7] Move region tags inside functions --- functions/helloworld/index.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/functions/helloworld/index.js b/functions/helloworld/index.js index fc0d09e0d0..adabaf341a 100644 --- a/functions/helloworld/index.js +++ b/functions/helloworld/index.js @@ -123,14 +123,15 @@ exports.helloGCSGeneric = (event, callback) => { * @param {object} event The Cloud Functions event. * @param {function} callback The callback function. */ -// [START functions_helloworld_error] + exports.helloError = (event, callback) => { + // [START functions_helloworld_error] // These WILL be reported to Stackdriver errors console.error('I failed you'); throw new Error('I failed you'); // Will cause a cold start if not caught -}; -// [END functions_helloworld_error] + // [END functions_helloworld_error] +}; /** * Background Cloud Function that throws a value. @@ -139,14 +140,15 @@ exports.helloError = (event, callback) => { * @param {function} callback The callback function. */ /* eslint-disable no-throw-literal */ -// [START functions_helloworld_error] + exports.helloError2 = (event, callback) => { + // [START functions_helloworld_error] // These will NOT be reported to Stackdriver errors console.info(new Error('I failed you')); // Logging an Error object at the info level console.error('I failed you'); // Logging something other than an Error object throw 1; // Throwing something other than an Error object + // [END functions_helloworld_error] }; -// [END functions_helloworld_error] /* eslint-enable no-throw-literal */ /** @@ -156,12 +158,12 @@ exports.helloError2 = (event, callback) => { * @param {function} callback The callback function. */ /* eslint-disable */ -// [START functions_helloworld_error] exports.helloError3 = (event, callback) => { // This will NOT be reported to Stackdriver errors + // [START functions_helloworld_error] callback('I failed you'); + // [END functions_helloworld_error] }; -// [END functions_helloworld_error] /* eslint-enable */ /** @@ -170,12 +172,12 @@ exports.helloError3 = (event, callback) => { * @param {Object} req Cloud Function request context. * @param {Object} res Cloud Function response context. */ -// [START functions_helloworld_error] exports.helloError4 = (req, res) => { // This will NOT be reported to Stackdriver errors + // [START functions_helloworld_error] res.status(500).send('I failed you'); + // [END functions_helloworld_error] }; -// [END functions_helloworld_error] // [START functions_helloworld_template] const path = require('path'); From e0a798d47759300da747cb9cd9e5cacba14a346f Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Thu, 17 May 2018 15:23:02 -0700 Subject: [PATCH 6/7] Fix typo --- functions/helloworld/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/helloworld/index.js b/functions/helloworld/index.js index adabaf341a..c69cb51d23 100644 --- a/functions/helloworld/index.js +++ b/functions/helloworld/index.js @@ -127,7 +127,7 @@ exports.helloGCSGeneric = (event, callback) => { exports.helloError = (event, callback) => { // [START functions_helloworld_error] // These WILL be reported to Stackdriver errors - console.error('I failed you'); + console.error(new Error('I failed you')); throw new Error('I failed you'); // Will cause a cold start if not caught // [END functions_helloworld_error] From 835c2cf875dfbea67af1896f14c9b9642efd8786 Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Mon, 23 Jul 2018 13:55:12 -0700 Subject: [PATCH 7/7] s/Errors/Error Reporting/ --- functions/helloworld/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functions/helloworld/index.js b/functions/helloworld/index.js index 5b63c86551..8f842f5617 100644 --- a/functions/helloworld/index.js +++ b/functions/helloworld/index.js @@ -162,7 +162,7 @@ exports.helloError2 = (event, callback) => { */ /* eslint-disable */ exports.helloError3 = (event, callback) => { - // This will NOT be reported to Stackdriver errors + // This will NOT be reported to Stackdriver Error Reporting // [START functions_helloworld_error] callback('I failed you'); // [END functions_helloworld_error] @@ -176,7 +176,7 @@ exports.helloError3 = (event, callback) => { * @param {Object} res Cloud Function response context. */ exports.helloError4 = (req, res) => { - // This will NOT be reported to Stackdriver errors + // This will NOT be reported to Stackdriver Error Reporting // [START functions_helloworld_error] res.status(500).send('I failed you'); // [END functions_helloworld_error]