Skip to content

Fix freply crash on unmatched braces - #3452

Open
lorenzo132 wants to merge 3 commits into
developmentfrom
users/lorenzo132/bracket-fix-freply
Open

Fix freply crash on unmatched braces#3452
lorenzo132 wants to merge 3 commits into
developmentfrom
users/lorenzo132/bracket-fix-freply

Conversation

@lorenzo132

Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings August 1, 2026 12:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the bot’s SafeFormatter to avoid crashing when user-provided format strings (notably freply) contain malformed/unmatched braces, by falling back to formatting only complete {field} occurrences instead of rejecting the entire message.

Changes:

  • Added a SafeFormatter.format() override that catches certain brace-related ValueErrors from string.Formatter.
  • Implemented a regex-based fallback that formats complete replacement fields individually and leaves malformed parts untouched.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread core/models.py
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: lorenzo132 <50767078+lorenzo132@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 1, 2026 12:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Suppressed comments (1)

core/models.py:373

  • The fallback path depends on exact ValueError message strings to decide whether to recover, which is brittle across Python versions. Additionally, the per-field formatter currently swallows any ValueError and returns the raw placeholder, which can silently hide real formatting errors (e.g., invalid format specs) whenever the message contains an unrelated unmatched brace.

Consider always attempting the safe per-field fallback on ValueError, but only suppressing ValueErrors that are truly brace-related; re-raise other ValueErrors so formatting errors aren’t silently ignored.

    def format(self, format_string, /, *args, **kwargs):
        try:
            return super().format(format_string, *args, **kwargs)
        except ValueError as exc:
            if str(exc) not in self._UNMATCHED_BRACE_ERRORS:

Copilot AI review requested due to automatic review settings August 1, 2026 12:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@sebkuip sebkuip left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sebkuip sebkuip added bug This is a confirmed bug pending review staged Staged for next version changelog Changes in PR have been added to draft release that will be used for the changelog on the next ver. labels Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug This is a confirmed bug changelog Changes in PR have been added to draft release that will be used for the changelog on the next ver. pending review staged Staged for next version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants