Scott Bender - @Teppo Kurki @bkeepers currentlu...

@Teppo Kurki @bkeepers currentluy with main branch I am getting
TypeError: Cannot read properties of undefined (reading 'forEach')
at /usr/local/src/signalk-server/dist/streambundle.js:70:39
at Array.forEach (<anonymous>)
at StreamBundle.pushDelta (/usr/local/src/signalk-server/dist/streambundle.js:52:31)
at FullSignalK.emit (node:events:518:28)
at FullSignalK.addDelta (/usr/local/src/signalk-server/node_modules/@signalk/signalk-schema/dist/fullsignalk.js:52:8)
at DeltaChain.doProcess (/usr/local/src/signalk-server/dist/deltachain.js:18:18)
at /usr/local/src/signalk-server/dist/deltachain.js:37:22
at Array.deltaInputHandler (/usr/local/src/test_server_config/node_modules/signalk-path-filter/dist/index.js:51:9)
at DeltaChain.doProcess (/usr/local/src/signalk-server/dist/deltachain.js:21:26)
at DeltaChain.process (/usr/local/src/signalk-server/dist/deltachain.js:14:21)
at Server.app.handleMessage (/usr/local/src/signalk-server/dist/index.js:241:38)
at Object.handleMessage (/usr/local/src/signalk-server/dist/interfaces/plugins.js:215:17)
at /usr/local/src/signalk-venus-plugin/index.js:716:17
at Array.forEach (<anonymous>)
at MqttClient.<anonymous> (/usr/local/src/signalk-venus-plugin/index.js:715:18)
at MqttClient.emit (node:events:518:28)
TypeError: Cannot read properties of undefined (reading 'forEach')
at /usr/local/src/signalk-server/dist/streambundle.js:70:39
at Array.forEach (<anonymous>)
at StreamBundle.pushDelta (/usr/local/src/signalk-server/dist/streambundle.js:52:31)
at FullSignalK.emit (node:events:518:28)
at FullSignalK.addDelta (/usr/local/src/signalk-server/node_modules/@signalk/signalk-schema/dist/fullsignalk.js:52:8)
at DeltaChain.doProcess (/usr/local/src/signalk-server/dist/deltachain.js:18:18)
at /usr/local/src/signalk-server/dist/deltachain.js:37:22
at Array.deltaInputHandler (/usr/local/src/test_server_config/node_modules/signalk-path-filter/dist/index.js:51:9)
at DeltaChain.doProcess (/usr/local/src/signalk-server/dist/deltachain.js:21:26)
at DeltaChain.process (/usr/local/src/signalk-server/dist/deltachain.js:14:21)
at Server.app.handleMessage (/usr/local/src/signalk-server/dist/index.js:241:38)
at Object.handleMessage (/usr/local/src/signalk-server/dist/interfaces/plugins.js:215:17)
at /usr/local/src/signalk-venus-plugin/index.js:716:17
at Array.forEach (<anonymous>)
at MqttClient.<anonymous> (/usr/local/src/signalk-venus-plugin/index.js:715:18)
at MqttClient.emit (node:events:518:28)
30 Replies
Teppo Kurki
Teppo Kurki3d ago
are you sure you have latest? https://github.com/SignalK/signalk-server/pull/1945 should have fixed that
GitHub
fix: fix streambundle error after port to TypeScript by bkeepers ·...
This fixes an error reported by @KEGustafsson introduced in #1918. I have not been able to recreate it, but apparently there are instances where update.values is present, but is not an array. Looki...
Scott Bender
Scott BenderOP3d ago
yes when I change that code if ('values' in update) { to if ( update.values ) it goes away the delta is
{"meta":[{"path":"electrical.venus.totalPanelCurrent","value":{"units":"A"}}],"$source":"venus","timestamp":"2025-04-29T12:42:45.104Z"}
{"meta":[{"path":"electrical.venus.totalPanelCurrent","value":{"units":"A"}}],"$source":"venus","timestamp":"2025-04-29T12:42:45.104Z"}
Teppo Kurki
Teppo Kurki3d ago
running with freshly pulled docker run -p 3000:3000 -it --rm signalk/signalk-server:master and entering
{
"updates": [
{
"meta": [
{
"path": "electrical.venus.totalPanelCurrent",
"value": {
"units": "A"
}
}
],
"values": [
{
"path": "electrical.venus.totalPanelCurrent",
"value": 3.14
}
],
"$source": "venus",
"timestamp": "2025-04-29T12:42:45.104Z"
}
]
}
{
"updates": [
{
"meta": [
{
"path": "electrical.venus.totalPanelCurrent",
"value": {
"units": "A"
}
}
],
"values": [
{
"path": "electrical.venus.totalPanelCurrent",
"value": 3.14
}
],
"$source": "venus",
"timestamp": "2025-04-29T12:42:45.104Z"
}
]
}
gives me the value in data browser as A's, no error messages. are you sure you've rebuilt everything?
Scott Bender
Scott BenderOP3d ago
don't include 'values' in that delta just meta
Teppo Kurki
Teppo Kurki3d ago
works that way too (just wanted values to verify that A makes it to metadata and is not silently swallowed)
Karl-Erik Gustafsson
Seeing the same issue as earlier, error comes only at startup from meta.
Scott Bender
Scott BenderOP3d ago
I get it when I send it via Data Browser this is a fresh repo today. tested with node v20 and v22 modified the code to
if ('values' in update) {
if ( !update.values ) {
console.log(JSON.stringify(update))
}
if ('values' in update) {
if ( !update.values ) {
console.log(JSON.stringify(update))
}
that message gets logged update.values is undefined, but that if ('values' in update) { check is passing am I crazy? hmm
{
meta: [ { path: 'electrical.solar.258.systemYield', value: [Object] } ],
'$source': 'venus',
timestamp: '2025-04-29T14:11:02.090Z',
values: undefined
}
{
meta: [ { path: 'electrical.solar.258.systemYield', value: [Object] } ],
'$source': 'venus',
timestamp: '2025-04-29T14:11:02.090Z',
values: undefined
}
so vaules is there, but it is undefined
Karl-Erik Gustafsson
At some phase streambunle.ts had fix in lines 66 and 77. Now those are gone from merged fix?
if ('meta' in update && Array.isArray(update.meta)) {
if ('meta' in update && Array.isArray(update.meta)) {
if ('values' in update && Array.isArray(update.values)) {
if ('values' in update && Array.isArray(update.values)) {
Teppo Kurki
Teppo Kurki3d ago
GitHub
signalk-server/src/index.ts at master · SignalK/signalk-server
An implementation of a Signal K central server for boats. - SignalK/signalk-server
Scott Bender
Scott BenderOP3d ago
that's index.ts it's not in streambundle.ts not loving this if ( 'x' in y ) syntax
Teppo Kurki
Teppo Kurki3d ago
the motivation is that after that ts can narrow the type down
Teppo Kurki
Teppo Kurki3d ago
but
No description
Scott Bender
Scott BenderOP3d ago
I don't know how values is getting set to undefined in this case...
Teppo Kurki
Teppo Kurki3d ago
...but i think ìf ( 'x' in y )` does not guard against the value being undefined and we need to add it everything that goes in streamdbundle should be coming through index.ts/handleMessage, i think? so that's the place to sanitise the data
Scott Bender
Scott BenderOP3d ago
makes sense, so you think we should change handleMessage to delete values if it is undefined? should it "sanitize" the whole delta?
Teppo Kurki
Teppo Kurki3d ago
yes, put it in the same if condition that i linked above now it sanitizes values and meta - and fills in timestamp etc so kinda does that too
Scott Bender
Scott BenderOP3d ago
I don't understand why this is not happening for you
Teppo Kurki
Teppo Kurki3d ago
ah, but !Array.isArray(undefined) should catch undefined already
Scott Bender
Scott BenderOP3d ago
hmm. wait, I don't see that sorry, it's there
Teppo Kurki
Teppo Kurki3d ago
check also in your dist/index.js
Scott Bender
Scott BenderOP3d ago
it's there
Teppo Kurki
Teppo Kurki3d ago
and after those checks you have data that has undefined as values? if you add the console.log there
Scott Bender
Scott BenderOP3d ago
debugging now... it's getting set to undefined some how after that handleMessage code... in toPreferredDelta? yep
update.values =
update.values &&
update.values.reduce((acc, pathValue) => {
update.values =
update.values &&
update.values.reduce((acc, pathValue) => {
Teppo Kurki
Teppo Kurki3d ago
how does that evaluate to undefined? values is always an array, so it reduces to an array
Scott Bender
Scott BenderOP3d ago
but it's not an array it's not there since this delta just has meta so update.values is undefined
Teppo Kurki
Teppo Kurki3d ago
GitHub
signalk-server/src/index.ts at 29cfc73018e49603b171322e441414f7bb72...
An implementation of a Signal K central server for boats. - SignalK/signalk-server
Scott Bender
Scott BenderOP3d ago
yeah, so it's not there so update.values evaluates to undefined this needs a if ( 'values' in update ) check
Teppo Kurki
Teppo Kurki3d ago
👍
Scott Bender
Scott BenderOP3d ago
PR coming... hmm. tests are not running? oh, there they go
Brandon Keepers
sorry, somehow I missed this whole thread

Did you find this page helpful?