Repository navigation
fix(subscribe): catch onChange errors and malformed bodies instead of crashing - #32
Merged
Merged
Conversation
… crashing The NATS read loop was a fire-and-forget async IIFE that called onChange unguarded, so a throwing or rejecting handler became an unhandled rejection and exited the host process. A body of "null" crashed it the same way, and an all-digit legacy hash parsed as a number and surfaced as "". Each delivery now runs in its own promise chain whose errors go to an onError option (default console.error), the loop itself is caught, and any body that is not an event object is treated as a bare version string. Fixes #16
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.
Fixes #16.
Problem.
subscribe()calledonChangewith no guard inside a fire-and-forget loop. A throwing or rejecting handler, including stub-agent'sawait client.get()failing during a reload, became an unhandled rejection and Node exited with code 1. A message body ofnullcrashed it the same way. An all-digit legacy hash parsed as a number and was delivered as"".Change
onErroroption,subscribe(uri, onChange, { onError }), which defaults toconsole.error. Deliveries stay concurrent, as before..catch(onError).null, a number) is treated as a bare version string.onError.The change is backward compatible: existing two-argument calls behave the same, except that they no longer crash.
Tested
nulland12345678bodies arrive. All four deliveries happen, both errors reachonError, and the versions come through as["v1","v2","null","12345678"].mainthe test fails with the escapedError: sync-ish handler bug.npm test: 14 of 14 pass.