Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MIDParser silently errors because _destroy() is a no-op #33

Open
ferm10n opened this issue May 30, 2022 · 1 comment
Open

MIDParser silently errors because _destroy() is a no-op #33

ferm10n opened this issue May 30, 2022 · 1 comment

Comments

@ferm10n
Copy link
Contributor

ferm10n commented May 30, 2022

I'm discovering that if there's an error during parsing, MidParser does not emit it, and the stream is silently destroyed. This might be caused by something I did while tinkering with the project, but it'd really help if I had some context about this section:

_destroy() {
//no-op, needed to handle older node versions
}

It seems to be responsible for why the error gets eaten. If I remove it, the default handler emits the error event correctly.

How did earlier versions of node behave that prompted _destroy() to become a noop? I'd like to fix this without breaking backwards compat, but can't do that without more history on why it was added.

(I'm using node v14 btw)

@ferm10n
Copy link
Contributor Author

ferm10n commented May 30, 2022

Additionally, I think that SessionControlClient should be modified to emit an error when calling close() with an error.

I tried removing the _destroy() noop mentioned above, but still didn't get an error.

Here's a sample output with `NODE_DEBUG=open-protocol`, with the changes mentioned
OPEN-PROTOCOL 24875: new MIDParser _transform {
  mid: 61,
  revision: 1,
  noAck: false,
  stationID: 1,
  spindleID: 1,
  sequenceNumber: 1,
  messageParts: 1,
  messageNumber: 1,
  payload: <Buffer 30 31 30 31 30 32 31 30 33 31 30 34 30 30 30 31 30 35 30 30 30 31 30 36 32 30 31 38 2d 31 32 2d 31 33 3a 31 33 3a 33 33 3a 35 31 30 31 30 30 30 35 30 ... 204 more bytes>
}
OPEN-PROTOCOL 24875: new MIDParser _transform err-parser {
  mid: 61,
  revision: 1,
  noAck: false,
  stationID: 1,
  spindleID: 1,
  sequenceNumber: 1,
  messageParts: 1,
  messageNumber: 1,
  payload: <Buffer 30 31 30 31 30 32 31 30 33 31 30 34 30 30 30 31 30 35 30 30 30 31 30 36 32 30 31 38 2d 31 32 2d 31 33 3a 31 33 3a 33 33 3a 35 31 30 31 30 30 30 35 30 ... 204 more bytes>
} Error: [Parser MID61] invalid key, mid: 61, parameter: channelID, expect: 2, receiver: 10 payload: {"cellID":102}
    at Object.parse (/home/jsanders/Documents/redviking/tmp-worktree/node-open-protocol/src/helpers.js:606:15)
    at Object.parser (/home/jsanders/Documents/redviking/tmp-worktree/node-open-protocol/src/mid/0061.js:235:35)
    at MIDParser._transform (/home/jsanders/Documents/redviking/tmp-worktree/node-open-protocol/src/MIDParser.js:44:29)
    at MIDParser.Transform._read (internal/streams/transform.js:205:10)
    at MIDParser.Transform._write (internal/streams/transform.js:193:12)
    at writeOrBuffer (internal/streams/writable.js:358:12)
    at MIDParser.Writable.write (internal/streams/writable.js:303:10)
    at LinkLayer._onDataOpParser (/home/jsanders/Documents/redviking/tmp-worktree/node-open-protocol/src/linkLayer.js:245:40)
    at OpenProtocolParser.<anonymous> (/home/jsanders/Documents/redviking/tmp-worktree/node-open-protocol/src/linkLayer.js:98:49)
    at OpenProtocolParser.emit (events.js:400:28)
OPEN-PROTOCOL 24875: LinkLayer _onErrorParser Error: Error on parser [Error: [Parser MID61] invalid key, mid: 61, parameter: channelID, expect: 2, receiver: 10 payload: {"cellID":102}]
    at /home/jsanders/Documents/redviking/tmp-worktree/node-open-protocol/src/MIDParser.js:48:24
    at Object.parser (/home/jsanders/Documents/redviking/tmp-worktree/node-open-protocol/src/mid/0061.js:325:5)
    at MIDParser._transform (/home/jsanders/Documents/redviking/tmp-worktree/node-open-protocol/src/MIDParser.js:44:29)
    at MIDParser.Transform._read (internal/streams/transform.js:205:10)
    at MIDParser.Transform._write (internal/streams/transform.js:193:12)
    at writeOrBuffer (internal/streams/writable.js:358:12)
    at MIDParser.Writable.write (internal/streams/writable.js:303:10)
    at LinkLayer._onDataOpParser (/home/jsanders/Documents/redviking/tmp-worktree/node-open-protocol/src/linkLayer.js:245:40)
    at OpenProtocolParser.<anonymous> (/home/jsanders/Documents/redviking/tmp-worktree/node-open-protocol/src/linkLayer.js:98:49)
    at OpenProtocolParser.emit (events.js:400:28)
OPEN-PROTOCOL 24875: SessionControlClient _onErrorLinkLayer Error: Error on parser [Error: [Parser MID61] invalid key, mid: 61, parameter: channelID, expect: 2, receiver: 10 payload: {"cellID":102}]
    at /home/jsanders/Documents/redviking/tmp-worktree/node-open-protocol/src/MIDParser.js:48:24
    at Object.parser (/home/jsanders/Documents/redviking/tmp-worktree/node-open-protocol/src/mid/0061.js:325:5)
    at MIDParser._transform (/home/jsanders/Documents/redviking/tmp-worktree/node-open-protocol/src/MIDParser.js:44:29)
    at MIDParser.Transform._read (internal/streams/transform.js:205:10)
    at MIDParser.Transform._write (internal/streams/transform.js:193:12)
    at writeOrBuffer (internal/streams/writable.js:358:12)
    at MIDParser.Writable.write (internal/streams/writable.js:303:10)
    at LinkLayer._onDataOpParser (/home/jsanders/Documents/redviking/tmp-worktree/node-open-protocol/src/linkLayer.js:245:40)
    at OpenProtocolParser.<anonymous> (/home/jsanders/Documents/redviking/tmp-worktree/node-open-protocol/src/linkLayer.js:98:49)
    at OpenProtocolParser.emit (events.js:400:28)
OPEN-PROTOCOL 24875: SessionControlClient close Error: Error on parser [Error: [Parser MID61] invalid key, mid: 61, parameter: channelID, expect: 2, receiver: 10 payload: {"cellID":102}]
    at /home/jsanders/Documents/redviking/tmp-worktree/node-open-protocol/src/MIDParser.js:48:24
    at Object.parser (/home/jsanders/Documents/redviking/tmp-worktree/node-open-protocol/src/mid/0061.js:325:5)
    at MIDParser._transform (/home/jsanders/Documents/redviking/tmp-worktree/node-open-protocol/src/MIDParser.js:44:29)
    at MIDParser.Transform._read (internal/streams/transform.js:205:10)
    at MIDParser.Transform._write (internal/streams/transform.js:193:12)
    at writeOrBuffer (internal/streams/writable.js:358:12)
    at MIDParser.Writable.write (internal/streams/writable.js:303:10)
    at LinkLayer._onDataOpParser (/home/jsanders/Documents/redviking/tmp-worktree/node-open-protocol/src/linkLayer.js:245:40)
    at OpenProtocolParser.<anonymous> (/home/jsanders/Documents/redviking/tmp-worktree/node-open-protocol/src/linkLayer.js:98:49)
    at OpenProtocolParser.emit (events.js:400:28)
OPEN-PROTOCOL 24875: LinkLayer _destroy

No error is ever emitted by the SessionControlClient.

Adding an emit('error') is easy enough in the close() method before emit('close') but does it makes sense? Would appreciate some input.

ferm10n pushed a commit to ferm10n/node-open-protocol that referenced this issue Jun 2, 2022
ferm10n pushed a commit to RV-Argonaut/node-open-protocol that referenced this issue Jun 2, 2022
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

No branches or pull requests

1 participant