From 54f6a20e2a895d91641e200cedd237331b08031f Mon Sep 17 00:00:00 2001 From: Sulka Haro Date: Mon, 30 Jul 2018 11:50:10 +0300 Subject: [PATCH 1/5] Log error on device status insert & don't crash --- lib/server/devicestatus.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/server/devicestatus.js b/lib/server/devicestatus.js index 3d925a56605..34b836a2561 100644 --- a/lib/server/devicestatus.js +++ b/lib/server/devicestatus.js @@ -10,6 +10,10 @@ function storage (collection, ctx) { obj.created_at = (new Date()).toISOString(); } api().insert(obj, function (err, doc) { + if (err != null && err.message) { + console.log('Error inserting the device status object', err.message); + return; + } fn(null, doc.ops); ctx.bus.emit('data-received'); }); From e622810094154dd66ab26f7126ab92dedfb77be6 Mon Sep 17 00:00:00 2001 From: Sulka Haro Date: Mon, 30 Jul 2018 12:33:04 +0300 Subject: [PATCH 2/5] Add error logging to all Mongo inserts --- lib/api/profile/index.js | 1 - lib/authorization/storage.js | 4 ++++ lib/server/activity.js | 4 ++++ lib/server/food.js | 4 ++++ lib/server/websocket.js | 12 ++++++++++++ 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/api/profile/index.js b/lib/api/profile/index.js index 07c6e1dc65a..30f8fe240ca 100644 --- a/lib/api/profile/index.js +++ b/lib/api/profile/index.js @@ -44,7 +44,6 @@ function configure (app, wares, ctx) { res.json(created.ops); console.log('Profile created', created); } - }); }); diff --git a/lib/authorization/storage.js b/lib/authorization/storage.js index 41969be150f..27a5acf6472 100644 --- a/lib/authorization/storage.js +++ b/lib/authorization/storage.js @@ -28,6 +28,10 @@ function init (env, ctx) { obj.created_at = (new Date()).toISOString(); } collection.insert(obj, function (err, doc) { + if (err != null && err.message) { + console.log('Data insertion error', err.message); + return; + } storage.reload(function loaded() { fn(null, doc.ops); }); diff --git a/lib/server/activity.js b/lib/server/activity.js index f7df9f48268..90a827e2e2d 100644 --- a/lib/server/activity.js +++ b/lib/server/activity.js @@ -9,6 +9,10 @@ function storage (env, ctx) { function create (obj, fn) { obj.created_at = (new Date( )).toISOString( ); api().insert(obj, function (err, doc) { + if (err != null && err.message) { + console.log('Activity data insertion error', err.message); + return; + } fn(null, doc.ops); }); } diff --git a/lib/server/food.js b/lib/server/food.js index 18a293690bf..7abc57b09de 100644 --- a/lib/server/food.js +++ b/lib/server/food.js @@ -6,6 +6,10 @@ function storage (env, ctx) { function create (obj, fn) { obj.created_at = (new Date( )).toISOString( ); api().insert(obj, function (err, doc) { + if (err != null && err.message) { + console.log('Data insertion error', err.message); + return; + } fn(null, doc.ops); }); } diff --git a/lib/server/websocket.js b/lib/server/websocket.js index 8143577c48e..5a24a49c6f8 100644 --- a/lib/server/websocket.js +++ b/lib/server/websocket.js @@ -338,6 +338,10 @@ function init (env, ctx, server) { // if not found create new record console.log(LOG_DEDUP + 'Adding new record'); ctx.store.collection(collection).insert(data.data, function insertResult (err, doc) { + if (err != null && err.message) { + console.log('Data insertion error', err.message); + return; + } if (callback) { callback(doc.ops); } @@ -367,6 +371,10 @@ function init (env, ctx, server) { } }); ctx.store.collection(collection).insert(data.data, function insertResult (err, doc) { + if (err != null && err.message) { + console.log('Data insertion error', err.message); + return; + } if (callback) { callback(doc.ops); } @@ -374,6 +382,10 @@ function init (env, ctx, server) { }); } else { ctx.store.collection(collection).insert(data.data, function insertResult (err, doc) { + if (err != null && err.message) { + console.log('Data insertion error', err.message); + return; + } if (callback) { callback(doc.ops); } From d231e37b806326bb3a682002c28598ca1a97cbcd Mon Sep 17 00:00:00 2001 From: Jeremy Cunningham Date: Tue, 16 Oct 2018 08:20:32 -0500 Subject: [PATCH 3/5] Return error when role or subject create fails. --- lib/authorization/storage.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/authorization/storage.js b/lib/authorization/storage.js index 27a5acf6472..9999b9f3178 100644 --- a/lib/authorization/storage.js +++ b/lib/authorization/storage.js @@ -30,6 +30,7 @@ function init (env, ctx) { collection.insert(obj, function (err, doc) { if (err != null && err.message) { console.log('Data insertion error', err.message); + fn(err.message, null); return; } storage.reload(function loaded() { From 140cc267059635caf8f7b38c3d6756f9d2977f86 Mon Sep 17 00:00:00 2001 From: Jeremy Cunningham Date: Tue, 16 Oct 2018 08:32:53 -0500 Subject: [PATCH 4/5] Return error if insert fails for activity, devicestatus, or food. --- lib/server/activity.js | 1 + lib/server/devicestatus.js | 1 + lib/server/food.js | 1 + 3 files changed, 3 insertions(+) diff --git a/lib/server/activity.js b/lib/server/activity.js index 90a827e2e2d..fba68cd0f5a 100644 --- a/lib/server/activity.js +++ b/lib/server/activity.js @@ -11,6 +11,7 @@ function storage (env, ctx) { api().insert(obj, function (err, doc) { if (err != null && err.message) { console.log('Activity data insertion error', err.message); + fn(err.message, null); return; } fn(null, doc.ops); diff --git a/lib/server/devicestatus.js b/lib/server/devicestatus.js index 34b836a2561..b07eb7fc125 100644 --- a/lib/server/devicestatus.js +++ b/lib/server/devicestatus.js @@ -12,6 +12,7 @@ function storage (collection, ctx) { api().insert(obj, function (err, doc) { if (err != null && err.message) { console.log('Error inserting the device status object', err.message); + fn(err.message, null); return; } fn(null, doc.ops); diff --git a/lib/server/food.js b/lib/server/food.js index 7abc57b09de..4369a0a4878 100644 --- a/lib/server/food.js +++ b/lib/server/food.js @@ -8,6 +8,7 @@ function storage (env, ctx) { api().insert(obj, function (err, doc) { if (err != null && err.message) { console.log('Data insertion error', err.message); + fn(err.message, null); return; } fn(null, doc.ops); From f64f6951f4cb0aca34519f71e16239a54c93c94a Mon Sep 17 00:00:00 2001 From: Jeremy Cunningham Date: Tue, 16 Oct 2018 13:26:29 -0500 Subject: [PATCH 5/5] Use unique log messages for insert database failures. (cherry picked from commit abd2044ef81e44817dd993ee47b0a9620874f7dc) --- lib/server/websocket.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/server/websocket.js b/lib/server/websocket.js index 5a24a49c6f8..db8797351e0 100644 --- a/lib/server/websocket.js +++ b/lib/server/websocket.js @@ -339,7 +339,7 @@ function init (env, ctx, server) { console.log(LOG_DEDUP + 'Adding new record'); ctx.store.collection(collection).insert(data.data, function insertResult (err, doc) { if (err != null && err.message) { - console.log('Data insertion error', err.message); + console.log('treatments data insertion error: ', err.message); return; } if (callback) { @@ -372,7 +372,7 @@ function init (env, ctx, server) { }); ctx.store.collection(collection).insert(data.data, function insertResult (err, doc) { if (err != null && err.message) { - console.log('Data insertion error', err.message); + console.log('devicestatus insertion error: ', err.message); return; } if (callback) { @@ -383,7 +383,7 @@ function init (env, ctx, server) { } else { ctx.store.collection(collection).insert(data.data, function insertResult (err, doc) { if (err != null && err.message) { - console.log('Data insertion error', err.message); + console.log(data.collection + ' insertion error: ', err.message); return; } if (callback) {