burnedikt / diasend-nightscout-bridge

Synchronize your diasend data to nightscout.
MIT License
18 stars 18 forks source link

Bridge crashing when attempting to delete treatment using internal nightscout api #41

Closed burnedikt closed 1 year ago

burnedikt commented 1 year ago

I've experienced a crash of the bridge today running as a nightscout plugin and using NS's internal API to push / delete treatments:

Version 2.0.2 of bridge

deduplicated treatments:  [
  {
    eventType: 'Meal Bolus',
    insulin: 0.3,
    carbs: undefined,
    notes: undefined,
    app: 'diasend',
    device: <retracted>',
    created_at: '2023-02-04T16:06:21.000Z'
  },
  {
    eventType: 'Temp Basal',
    absolute: 0.2,
    duration: 360,
    app: 'diasend',
    device: <retracted>',
    created_at: '2023-02-04T16:22:50.000Z'
  }
]
merged meal boli:  [
  {
    eventType: 'Meal Bolus',
    insulin: 0.3,
    carbs: 7,
    notes: undefined,
    app: 'diasend',
    device: <retracted>',
    created_at: '2023-02-04T16:06:21.000Z',
    carbsReference: '2023-02-04T16:06:09.000Z 7g'
  }
]
merged carb corrections:  [
  {
    _id: 63de82a848aec4a88ed8fe15,
    eventType: 'Carb Correction',
    carbs: 7,
    app: 'diasend',
    device: <retracted>',
    created_at: '2023-02-04T16:06:09.000Z',
    utcOffset: 0
  }
]
Sending 2 new treatments to nightscout
Removing 1 treatments from nightscout
Treatment delay (seconds) for 75 {
  eventType: 'Temp Basal',
  absolute: 0.2,
  duration: 360,
  app: 'diasend',
  device: <retracted>',
  created_at: '2023-02-04T16:22:50.000Z'
}
Treatment delay (seconds) for 1064 {
  eventType: 'Meal Bolus',
  insulin: 0.3,
  carbs: 7,
  notes: undefined,
  app: 'diasend',
  device: <retracted>',
  created_at: '2023-02-04T16:06:21.000Z',
  carbsReference: '2023-02-04T16:06:09.000Z 7g'
}
/opt/app/node_modules/mongodb/lib/utils.js:106
throw err;
^
TypeError: Cannot read property '_id' of undefined
at /opt/app/lib/server/treatments.js:133:30
at /opt/app/node_modules/mongodb/lib/utils.js:384:17
at /opt/app/node_modules/mongodb/lib/utils.js:372:11
at ClientSession.endSession (/opt/app/node_modules/mongodb/lib/core/sessions.js:146:41)
at executeCallback (/opt/app/node_modules/mongodb/lib/utils.js:369:17)
at handleCallback (/opt/app/node_modules/mongodb/lib/utils.js:102:55)
at /opt/app/node_modules/mongodb/lib/operations/common_functions.js:322:5
at handler (/opt/app/node_modules/mongodb/lib/core/sdam/topology.js:942:24)
at /opt/app/node_modules/mongodb/lib/cmap/connection_pool.js:356:13
at handleOperationResult (/opt/app/node_modules/mongodb/lib/core/sdam/server.js:558:5)
widmann commented 1 year ago

Same/similar here. Unfortunately, the crash appears to be related to loss of data. About 5 days of treatment data were lost. I don't know for sure if the crash was the cause, at least it was coincident.

deduplicated treatments:  [
{
eventType: 'Meal Bolus',
insulin: 3.5,
carbs: undefined,
notes: undefined,
app: 'diasend',
device: '<retracted>',
created_at: '2023-02-08T07:43:00.000Z'
},
{
eventType: 'Temp Basal',
absolute: 0.55,
duration: 360,
app: 'diasend',
device: '<retracted>',
created_at: '2023-02-08T07:50:27.000Z'
}
]
merged meal boli:  [
{
eventType: 'Meal Bolus',
insulin: 3.5,
carbs: 20,
notes: undefined,
app: 'diasend',
device: '<retracted>',
created_at: '2023-02-08T07:43:00.000Z',
carbsReference: '2023-02-08T07:39:44.000Z 20g'
}
]
merged carb corrections:  [
{
_id: 63e352db419663a6f1031d91,
eventType: 'Carb Correction',
carbs: 20,
app: 'diasend',
device: '<retracted>',
created_at: '2023-02-08T07:39:44.000Z',
utcOffset: 0
}
]
Sending 2 new treatments to nightscout
Removing 1 treatments from nightscout
Treatment delay (seconds) for 127 {
eventType: 'Temp Basal',
absolute: 0.55,
duration: 360,
app: 'diasend',
device: '<retracted>',
created_at: '2023-02-08T07:50:27.000Z'
}
Treatment delay (seconds) for 574 {
eventType: 'Meal Bolus',
insulin: 3.5,
carbs: 20,
notes: undefined,
app: 'diasend',
device: '<retracted>',
created_at: '2023-02-08T07:43:00.000Z',
carbsReference: '2023-02-08T07:39:44.000Z 20g'
}
(node:1) DeprecationWarning: collection.remove is deprecated. Use deleteOne, deleteMany, or bulkWrite instead.
got data-received event, requesting reload
/opt/app/node_modules/mongodb/lib/utils.js:106
throw err;
^
TypeError: Cannot read property '_id' of undefined
at /opt/app/lib/server/treatments.js:133:30
at /opt/app/node_modules/mongodb/lib/utils.js:384:17
at /opt/app/node_modules/mongodb/lib/utils.js:372:11
at ClientSession.endSession (/opt/app/node_modules/mongodb/lib/core/sessions.js:146:41)
at executeCallback (/opt/app/node_modules/mongodb/lib/utils.js:369:17)
at handleCallback (/opt/app/node_modules/mongodb/lib/utils.js:102:55)
at /opt/app/node_modules/mongodb/lib/operations/common_functions.js:322:5
at handler (/opt/app/node_modules/mongodb/lib/core/sdam/topology.js:942:24)
at /opt/app/node_modules/mongodb/lib/cmap/connection_pool.js:356:13
at handleOperationResult (/opt/app/node_modules/mongodb/lib/core/sdam/server.js:558:5)
burnedikt commented 1 year ago

Indeed this was a wrong implementation of how treatments are fetched and deleted via Nightscout's internal api.

Fixed in 2.0.4.