-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
fix: check if message can be handled before attempting to deserialize #5927
Conversation
How about a slightly different approach? diff --git a/contrib/message-capture/message-capture-parser.py b/contrib/message-capture/message-capture-parser.py
index 33759ee71..c47685730 100755
--- a/contrib/message-capture/message-capture-parser.py
+++ b/contrib/message-capture/message-capture-parser.py
@@ -122,8 +122,8 @@ def process_file(path: str, messages: List[Any], recv: bool, progress_bar: Optio
msg_ser = BytesIO(f_in.read(length))
# Determine message type
- if msgtype not in MESSAGEMAP:
- # Unrecognized message type
+ if msgtype not in MESSAGEMAP or MESSAGEMAP[msgtype] is None:
+ # Unrecognized or unhandled message type
try:
msgtype_tmp = msgtype.decode()
if not msgtype_tmp.isprintable():
@@ -131,10 +131,11 @@ def process_file(path: str, messages: List[Any], recv: bool, progress_bar: Optio
msg_dict["msgtype"] = msgtype_tmp
except UnicodeDecodeError:
msg_dict["msgtype"] = "UNREADABLE"
+ err_str = "Unrecognized" if msgtype not in MESSAGEMAP else "Unhandled"
msg_dict["body"] = msg_ser.read().hex()
- msg_dict["error"] = "Unrecognized message type."
+ msg_dict["error"] = f"{err_str} message type"
messages.append(msg_dict)
- print(f"WARNING - Unrecognized message type {msgtype} in {path}", file=sys.stderr)
+ print(f"WARNING - {msg_dict['error']} {msgtype} in {path}", file=sys.stderr)
continue
# Deserialize the message This way you'd get unhandled messages in the list too. Their Example:
|
Thanks 👍 Your solution is preferable imo 🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK for squash merge
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK
Co-authored-by: UdjinM6 <[email protected]>
6c76b0a
to
afbae06
Compare
…pting to deserialize afbae06 fix: check if message can be handled before attempting to deserialize (thephez) Pull request description: ## Issue being fixed or feature implemented Currently `message-capture-parser.py` crashes when encountering certain messages (e.g. mnauth). This at least makes it possible to run the script without crashing. There may be better options for solving this. ## What was done? Check if the dictionary is going to return `None` before we attempt to do something further with it. Hide whitespace changes to see the few lines that were added: https://github.com/dashpay/dash/pull/5927/files?diff=unified&w=1 ## How Has This Been Tested? Running script locally ## Breaking Changes N/A ## Checklist: _Go over all the following points, and put an `x` in all the boxes that apply._ - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [ ] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ Top commit has no ACKs. Tree-SHA512: 041af57afcfd1d93487fd41d34a50e3a99f7fa129563dfe1e1cf2498974c8e658bd6acb9c810887c841160074056ba999e9b6607ac9336b98b9d42806682c607
…pting to deserialize afbae06 fix: check if message can be handled before attempting to deserialize (thephez) Pull request description: ## Issue being fixed or feature implemented Currently `message-capture-parser.py` crashes when encountering certain messages (e.g. mnauth). This at least makes it possible to run the script without crashing. There may be better options for solving this. ## What was done? Check if the dictionary is going to return `None` before we attempt to do something further with it. Hide whitespace changes to see the few lines that were added: https://github.com/dashpay/dash/pull/5927/files?diff=unified&w=1 ## How Has This Been Tested? Running script locally ## Breaking Changes N/A ## Checklist: _Go over all the following points, and put an `x` in all the boxes that apply._ - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [ ] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ Top commit has no ACKs. Tree-SHA512: 041af57afcfd1d93487fd41d34a50e3a99f7fa129563dfe1e1cf2498974c8e658bd6acb9c810887c841160074056ba999e9b6607ac9336b98b9d42806682c607
b96b202 chore: bump version to 20.1.1 (pasta) 83cac77 docs: add v20.1.1 release notes (pasta) e58c7c4 Merge #5970: guix: exclude debug symbols for apple from list of hashes due to its non-determinism (pasta) 2bde1dd Merge #5927: fix: check if message can be handled before attempting to deserialize (pasta) 1637fa5 Merge #5968: docs: add v20.0.4 release notes (pasta) fd46c4c Merge #5962: fix: deadlock over cs_main and contributionsCacheCs in dkssessionmgr (pasta) Pull request description: ## Issue being fixed or feature implemented Backport to v20.1.x and release v20.1.1 ## What was done? Backports and release ## How Has This Been Tested? ## Breaking Changes None ## Checklist: _Go over all the following points, and put an `x` in all the boxes that apply._ - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ Top commit has no ACKs. Tree-SHA512: 40574df3349bf1c653a50b4efbf78d1654eb048eeeb483eb657eec5f2af102f95cff8f978a98c174925d2672d56426238a1b7ec3e8cd2a53ec28c0fca42c1293
b96b202 chore: bump version to 20.1.1 (pasta) 83cac77 docs: add v20.1.1 release notes (pasta) e58c7c4 Merge #5970: guix: exclude debug symbols for apple from list of hashes due to its non-determinism (pasta) 2bde1dd Merge #5927: fix: check if message can be handled before attempting to deserialize (pasta) 1637fa5 Merge #5968: docs: add v20.0.4 release notes (pasta) fd46c4c Merge #5962: fix: deadlock over cs_main and contributionsCacheCs in dkssessionmgr (pasta) Pull request description: Merge master into develop Top commit has no ACKs. Tree-SHA512: e65ffefcb7d0e92367ff322cab533f8505f0e9d00ab136bccb1dbf86ad64d6b710b5c9f9943594c544827d2eb69f5d0ba185962a2ac0b16c6b776a94f44cfb42
…pting to deserialize afbae06 fix: check if message can be handled before attempting to deserialize (thephez) Pull request description: ## Issue being fixed or feature implemented Currently `message-capture-parser.py` crashes when encountering certain messages (e.g. mnauth). This at least makes it possible to run the script without crashing. There may be better options for solving this. ## What was done? Check if the dictionary is going to return `None` before we attempt to do something further with it. Hide whitespace changes to see the few lines that were added: https://github.com/dashpay/dash/pull/5927/files?diff=unified&w=1 ## How Has This Been Tested? Running script locally ## Breaking Changes N/A ## Checklist: _Go over all the following points, and put an `x` in all the boxes that apply._ - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [ ] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ Top commit has no ACKs. Tree-SHA512: 041af57afcfd1d93487fd41d34a50e3a99f7fa129563dfe1e1cf2498974c8e658bd6acb9c810887c841160074056ba999e9b6607ac9336b98b9d42806682c607
Issue being fixed or feature implemented
Currently
message-capture-parser.py
crashes when encountering certain messages (e.g. mnauth). This at least makes it possible to run the script without crashing. There may be better options for solving this.What was done?
Check if the dictionary is going to return
None
before we attempt to do something further with it. Hide whitespace changes to see the few lines that were added: https://github.com/dashpay/dash/pull/5927/files?diff=unified&w=1How Has This Been Tested?
Running script locally
Breaking Changes
N/A
Checklist:
Go over all the following points, and put an
x
in all the boxes that apply.