fix: keep the taker message deliverable when MarkdownV2 parsing fails - #914
fix: keep the taker message deliverable when MarkdownV2 parsing fails#914ToRyVand wants to merge 2 commits into
Conversation
A single unescaped MarkdownV2 reserved character in a translation makes Telegram reject the send. In beginTakeSellMessage that send is followed by the message carrying the order's Continue/Cancel buttons, so the throw was caught by the outer handler and the buttons were never sent: the taker was left both without the confirmation text and without any way to advance or cancel the order until it expired. Send the message through a helper that retries once without parse_mode when Telegram rejects the formatting, and log the offending locale so the translation can be corrected. Escaping locales (as in lnp2pBot#872) fixes the known characters; this keeps the flow usable when a new one slips through. Adds a regression test asserting the plain-text retry and, most importantly, that the action buttons are still delivered. Closes lnp2pBot#882
Two refinements to the MarkdownV2 fallback: - The retry re-sent the MarkdownV2 source verbatim, so the reader saw the now-meaningless backslash escapes the locales carry (`\.`, `\(`) right in the funds-risk warning. Strip them before sending as plain text. - The catch retried on any error. A network failure may mean the message was already delivered (duplicating a long warning), a 429 retry ignores retry_after, and a 403 retry is guaranteed to fail. Narrow the fallback to Telegram's 400 "can't parse entities" and re-throw everything else so the existing handler deals with it as before. Extends the spec with the escape-stripping assertion and a case proving non-formatting errors are not retried.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
WalkthroughThe buyer notification flow now retries Telegram MarkdownV2 parse failures as plain text after removing escapes. Other errors remain unchanged. Tests cover fallback retries, action buttons, non-formatting errors, and safe localized messages. ChangesMarkdownV2 fallback
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Closes #882.
When a translation contains an unescaped MarkdownV2 reserved character, Telegram rejects the
you_took_someone_ordersend. BecausebeginTakeSellMessagesends the order's Continue/Cancel buttons right after, the throw was caught by the outer handler and the buttons were never sent — so the taker was left not only without the confirmation text, but without any way to advance or cancel the order until it expired. That's the part worth highlighting: the impact is a stuck trade, not just a missing message.Approach
The send now goes through a small helper that retries once without
parse_modewhen Telegram returns 400can't parse entities, so the flow continues and the buttons are delivered.retry_after, or repeat a call guaranteed to fail. This follows the existingerror instanceof TelegramError && error.response.error_code === …pattern in this file.\./\(escapes that are meaningless withoutparse_mode; sending verbatim would show stray backslashes in the funds-risk warning.This complements #872 (escaping the Farsi locale) rather than replacing it: escaping fixes the known characters, this keeps the flow usable if a new one slips through.
Note (not addressed here)
onGoingTakeSellMessagehas the same shape — a MarkdownV2 send sitting before the seller's "your order was taken" notification. It's latent today (/fiatsentis safe in all ten locales), so I left it out to keep this scoped to the reported bug. Happy to apply the same helper there if you'd prefer.Local validation
Tests cover the plain-text retry, that the action buttons are still delivered, that non-formatting errors are not retried, and that MarkdownV2 is preserved when the locale is safe. Verified the regression test fails without the fix (only 1 send happens; the buttons never go out).
Summary by CodeRabbit
Bug Fixes
Tests