Fix TypeError in requestMetaData when n2kOut is not available#307
Open
dirkwa wants to merge 1 commit intoSignalK:masterfrom
Open
Fix TypeError in requestMetaData when n2kOut is not available#307dirkwa wants to merge 1 commit intoSignalK:masterfrom
dirkwa wants to merge 1 commit intoSignalK:masterfrom
Conversation
requestMetaData() calls this.n2kListener.emit() but n2kListener is only set when n2kOutIsAvailable() is called. If a device changes its N2K source address (PGN 60928 with a different CAN name) before n2kOut becomes available, toDelta() calls requestMetaData() and crashes with: TypeError: Cannot read properties of undefined (reading 'emit') Add a guard to return early if n2kListener is not yet initialized.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
requestMetaData()crashes withTypeError: Cannot read properties of undefined (reading 'emit')whenthis.n2kListeneris not yet initializedn2kOutIsAvailable()has been calledn2kListeneris not setHow to reproduce
On a CAN bus with many devices, an address claim conflict can cause a device to change its source address. When this happens before NMEA2000 output is available,
toDelta()callsrequestMetaData()which crashes:Fix
Guard
requestMetaData()to return early (with a resolved promise) whenn2kListeneris undefined, instead of crashing. The metadata request will simply be skipped — oncen2kOutIsAvailable()is eventually called,requestAllMeta()will request metadata for all known sources anyway.