Skip to content

Conversation

@jpcunningh
Copy link
Contributor

Under certain circumstances when NS has glucose calibration records, cob.js will crash due to avgDelta being undefined.

This PR updates the logic to avoid avgDelta the error causing the crash.

@jpcunningh
Copy link
Contributor Author

For reference, the crash is:

/root/src/oref0/lib/determine-basal/cob.js:129
        avgDelta = avgDelta.toFixed(2);
                            ^

TypeError: Cannot read property 'toFixed' of undefined
    at detectCarbAbsorption (/root/src/oref0/lib/determine-basal/cob.js:129:29)
    at /root/src/oref0/lib/meal/total.js:68:39
    at Array.forEach (<anonymous>)
    at recentCarbs (/root/src/oref0/lib/meal/total.js:46:16)
    at generate (/root/src/oref0/lib/meal/index.js:20:19)
    at Object.<anonymous> (/root/src/oref0/bin/oref0-meal.js:97:23)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)

} else if (glucose_data[i-1].dateString) {
lastbgTime = new Date(glucose_data[i-1].dateString);
} else { console.error("Could not determine last BG time"); }
if (! glucose_data[i].glucose || glucose_data[i].glucose < 39 || glucose_data[i-1].glucose < 39) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove this instead of modifying it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 41-47 were moved lower and lines 48 and 49 were modified to remove the check against the glucose_data[i-1].glucose value and are now lines 47 and 48.

The [i-1] check is no longer required due to how lastbgi is managed.

@scottleibrand scottleibrand merged commit 6d5aaa0 into openaps:dev Aug 15, 2018
@jpcunningh jpcunningh deleted the fix-cob.js-crash branch August 16, 2018 02:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants