Skip to content

Make error messages for using font.align clearer #2777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 30, 2024

Conversation

Kn4ughty
Copy link
Contributor

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.

@Kn4ughty Kn4ughty requested a review from a team as a code owner March 28, 2024 01:46
@oddbookworm
Copy link
Member

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

Copy link
Member

@oddbookworm oddbookworm left a comment

Choose a reason for hiding this comment

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

LGTM! The CI fails due to a missing dependency are weird and I've mentioned the fails to @ankith26 (the CI guru). Hopefully something can be done to fix those soon

@Starbuck5
Copy link
Member

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

Copy link
Member

@ankith26 ankith26 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for contributing 😎

@ankith26 ankith26 added font pygame.font enhancement labels Mar 29, 2024
@Kn4ughty Kn4ughty closed this Mar 30, 2024
@Kn4ughty Kn4ughty reopened this Mar 30, 2024
@ankith26 ankith26 merged commit c1708da into pygame-community:main Mar 30, 2024
@ankith26 ankith26 added this to the 2.5.0 milestone Mar 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants