fix: check if message can be handled before attempting to deserialize#5927
Merged
PastaPastaPasta merged 1 commit intodashpay:developfrom Mar 12, 2024
Merged
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 messageThis way you'd get unhandled messages in the list too. Their Example: |
Collaborator
Author
Thanks 👍 Your solution is preferable imo 🙂 |
UdjinM6
requested changes
Mar 11, 2024
PastaPastaPasta
approved these changes
Mar 12, 2024
Member
PastaPastaPasta
left a comment
There was a problem hiding this comment.
utACK for squash merge
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
6c76b0a to
afbae06
Compare
PastaPastaPasta
added a commit
to PastaPastaPasta/dash
that referenced
this pull request
Apr 3, 2024
…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
PastaPastaPasta
added a commit
that referenced
this pull request
Apr 3, 2024
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
PastaPastaPasta
added a commit
that referenced
this pull request
Apr 9, 2024
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
davideludu
pushed a commit
to 6zip-project/6zip
that referenced
this pull request
Jul 18, 2024
…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
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.
Issue being fixed or feature implemented
Currently
message-capture-parser.pycrashes 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
Nonebefore 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
xin all the boxes that apply.