Skip to content

Commit

Permalink
feature: add detail to delta error
Browse files Browse the repository at this point in the history
Previously if the delta was missing a path or value, the logged error message
was "Illegal value in delta: " along witht the pathValue. This is a bit misleading.

The new error message provides detail about whether the path and/or value is
missing along with source info.

Example of new message:
Delta is missing path in {"value":294.17}
from source {"label":"ydwg-2000","type":"NMEA2000","pgn":130312,"src":"41","instance":"0"}
  • Loading branch information
jncarter123 authored and tkurki committed Nov 3, 2021
1 parent 1f3b513 commit ace24a8
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/fullsignalk.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function handleNmea2000Source(labelSource, source, timestamp) {
delete existing.n2k.label
delete existing.n2k.instance
delete existing.n2k.type

if(source.instance && !labelSource[source.src][source.instance]) {
labelSource[source.src][source.instance] = {}
}
Expand Down Expand Up @@ -189,10 +189,23 @@ function addValues(context, contextPath, source, timestamp, pathValues) {
}

function addValue(context, contextPath, source, timestamp, pathValue) {
if (_.isUndefined(pathValue.path) || _.isUndefined(pathValue.value)) {
console.error("Illegal value in delta:" + JSON.stringify(pathValue));
let errMessage = ""
if(_.isUndefined(pathValue.path)){
errMessage += "path"
}

if(_.isUndefined(pathValue.value)){
errMessage += errMessage.length > 0 ? " and value" : "value"
}

if(errMessage.length > 0){
errMessage = "Delta is missing " + errMessage + " in " + JSON.stringify(pathValue)
errMessage += " from source " + JSON.stringify(source)

console.error(errMessage);
return;
}

var valueLeaf;
if(pathValue.path.length === 0) {
_.merge(context, pathValue.value)
Expand Down

0 comments on commit ace24a8

Please sign in to comment.