Skip to content

Fix crash when rendering quote images with multiline author - #137

Merged
cfazilleau merged 1 commit into
unstablefrom
claude/new-session-2jpw1p
Sep 13, 2026
Merged

cfazilleau merged 1 commit into
unstablefrom
claude/new-session-2jpw1p

Conversation

@cfazilleau

Copy link
Copy Markdown
Owner

Summary

The /quote command crashed with ValueError: can't measure length of multiline text whenever a quote's author contained a newline character.

PIL's draw.textlength() refuses any string containing \n. In quote_image.py, the author line was built directly from the stored author value (f'— {author}'). A stored author can contain newlines (Discord display names allow them, and older stored quotes may carry them), which produced a multiline string and crashed get_text_length()draw.textlength(), taking down the whole command.

Changes

  • Hardened get_text_length() to measure each line and return the widest, so it can never crash on multiline input regardless of source (quote or author).
  • Normalized the author to a single line by collapsing embedded newlines/whitespace, so it renders and centers cleanly at the bottom of the image.

Testing

  • Verified the file compiles with python -m py_compile cogs/quotes/quote_image.py.

Traceback (before fix)

File "/app/cogs/quotes/quote_image.py", line 78, in _render
    ax = int((IMG_W - get_text_length(draw, author_str, font_author)) // 2)
File "/app/cogs/quotes/quote_image.py", line 19, in get_text_length
    return draw.textlength(clean_text, font=font)
ValueError: can't measure length of multiline text

🤖 Generated with Claude Code


Generated by Claude Code

draw.textlength() raises ValueError ("can't measure length of multiline
text") when given text containing newlines. A stored quote author can
contain newline characters, which produced a multiline author string and
crashed the /quote command.

Harden get_text_length() to measure the widest line instead of failing,
and normalize the author to a single line so it renders and centers
cleanly.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RKmj7PMxqNgWnprxf5GfpT
@cfazilleau
cfazilleau merged commit 5857e4b into unstable Sep 13, 2026
@cfazilleau
cfazilleau deleted the claude/new-session-2jpw1p branch September 13, 2026 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants