pygame-community / pygame-ce

🐍🎮 pygame - Community Edition is a FOSS Python library for multimedia applications (like games). Built on top of the excellent SDL library.
https://pyga.me
853 stars 140 forks source link

Make error messages for using font.align clearer #2777

Closed Kn4ughty closed 6 months ago

Kn4ughty commented 6 months ago

Hello, while using font.align in a project, I passed it bad data, and the error message was not clear, and I had to read the source code to work out what the error message actually meant. The problem is when you pass something that is not FONT_LEFT, FONT_CENTER, or FONT_RIGHT it says it must be an integer, but to the end user it might appear that FONT_LEFT is not an integer, and they might be confused about what they need to parse.

I had a function that drew some text, and it was something like this

self.fontObj.align = self.textJustify

Then when i passed it the wrong type, the error message said it must be an integer, and I thought "I thought it was pygame.FONT_LEFT!"

I hope that this change makes it more clear to any users in the future.

oddbookworm commented 6 months ago

The CI fails I'm seeing so far are concerning (not to do with your code though)

Starbuck5 commented 6 months ago

The error message is missing spaces in necessary locations:

>>> a.align = -1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
pygame.error: font.align must be FONT_LEFT, FONT_CENTER, orFONT_RIGHT.
>>> a.align = "hello"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: font.align must be an integer.Must correspond with FONT_LEFT, FONT_CENTER, or FONT_RIGHT