Skip to content

Commit 0bcf2f1

Browse files
authored
Merge pull request #226 from david-lev/dev
Improve error handling in message sending and add CLI tests
2 parents c6175b3 + 3001a1c commit 0bcf2f1

3 files changed

Lines changed: 493 additions & 4 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ include = ["pywa_async/**"]
145145
invalid-method-override = "ignore"
146146

147147
[tool.coverage.run]
148-
source = ["pywa", "pywa_async"]
148+
include = ["pywa/*", "pywa_async/*"]
149149
omit = ["pywa/__main__.py"]
150150

151151
[tool.coverage.report]

pywa/cli.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from . import __version__ as pywa_version
2323
from ._logging import ENV_LOG_LEVEL, format_banner, setup_console_logging
2424
from .client import WhatsApp
25+
from .errors import SendMessageError
2526

2627
GITHUB_REPO = "david-lev/pywa"
2728
GITHUB_API_BASE = "https://api.github.com/repos"
@@ -289,11 +290,14 @@ def send_messages(
289290
f"✅ [{index + 1}/{len(to)}] Sent {send_type} to {recipient} (Msg ID: {sent.id})"
290291
)
291292

292-
# one recipient's failure shouldn't abort the batch
293-
except Exception as e: # noqa: BLE001
293+
except SendMessageError as e:
294294
print(
295295
f"❌ [{index + 1}/{len(to)}] Failed to send {send_type} to {recipient}: {e}"
296296
)
297+
except Exception as e:
298+
raise PywaCLIException(
299+
f"Unexpected error while sending {send_type} to {recipient}: {e}"
300+
) from e
297301

298302

299303
DEFAULT_PROJECT = """from pywa_async import WhatsApp, filters, types, utils

0 commit comments

Comments
 (0)