Skip to content

Commit 3e5bc26

Browse files
authored
Fix MSP callback on crc error (#4665)
1 parent cba81c4 commit 3e5bc26

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/js/msp/MSPHelper.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,13 +1779,17 @@ MspHelper.prototype.process_data = function (dataHandler) {
17791779

17801780
// remove object from array
17811781
dataHandler.callbacks.splice(i, 1);
1782-
if (!crcError) {
1783-
// fire callback
1784-
if (callback) {
1785-
callback({ command: code, data: data, length: data.byteLength, crcError: crcError });
1782+
// Always invoke callback and pass crcError flag. Callbacks expect to
1783+
// receive the original DataView so they can choose how to handle CRC
1784+
// errors; don't replace the data with null here to avoid breaking
1785+
// existing consumers that dereference response.data before checking
1786+
// crcError.
1787+
if (callback) {
1788+
try {
1789+
callback({ command: code, data: data, length: data ? data.byteLength : 0, crcError: crcError });
1790+
} catch (e) {
1791+
console.error(`callback for code ${code} threw:`, e);
17861792
}
1787-
} else {
1788-
console.warn(`code: ${code} - crc failed. No callback`);
17891793
}
17901794
}
17911795
}

0 commit comments

Comments
 (0)