Skip to contentSkip to conversation

Avoid type error when local mbox lacks specified message ID

PATCH Applied Kyle Meyer 2 participants 2 messages May 23, 2021 – May 25, 2021

lore
Share & tools
lore

Kyle Meyer

author
#0 lore raw

PATCH 1/1 Avoid type error when local mbox lacks specified message ID

Calling b4-am with --use-local=MBOX is supposed to abort with "Could not find MID in MBOX" if the mbox doesn't contain the specified message ID. As of 4950093c0 (Don't use mboxo for anything, 2021-05-18), a type error is signaled because get_strict_thread() returns None when there are no matches, and get_msgs() feeds this result to len().

Update get_msgs() to instead check whether the returned value evaluates to false.

---
 b4/mbox.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
b4/mbox.py +1 -1
index a4b005f..bf1a586 100644
@@ -572,7 +572,7 @@ def get_msgs(cmdargs) -> Tuple[Optional[str], Optional[list]]:
 
             if msgid:
                 msgs = b4.get_strict_thread(in_mbx, msgid)
-                if not len(msgs):
+                if not msgs:
                     logger.critical('Could not find %s in %s', msgid, cmdargs.localmbox)
                     sys.exit(1)
             else:

base-commit: 7ed8a3cafd5f3ba5b4e914b495bb3035428e2d45

Signature · 1 line
2.31.1
#1 lore raw
Quoted 8 lines · Kyle Meyer

Calling b4-am with --use-local=MBOX is supposed to abort with "Could not find MID in MBOX" if the mbox doesn't contain the specified message ID. As of 4950093c0 (Don't use mboxo for anything, 2021-05-18), a type error is signaled because get_strict_thread() returns None when there are no matches, and get_msgs() feeds this result to len().

[...]

Applied, thanks!

[1/1] Avoid type error when local mbox lacks specified message ID

      commit: 5d6e3d8e47af6c787ca2cc32e873478fb5c3ba55

I should really refactor that part of the code to properly throw exceptions instead of returning None. My head is a bit of a mishmash of "Python best practices from 2003," back when throwing exceptions was considered "too slow." I'm getting better, though -- who knows, I may even finally add a test suite. :)

Best regards,

Signature · 1 line
Konstantin Ryabitsev <[email protected]>