Skip to content
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

draw_text() producing unclear IndexError #36

Open
doglman opened this issue Jul 17, 2023 · 0 comments
Open

draw_text() producing unclear IndexError #36

doglman opened this issue Jul 17, 2023 · 0 comments
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@doglman
Copy link

doglman commented Jul 17, 2023

While using the draw_text() function, I found I was regularly violating the preconditions of this function, which had not been communicated to me, producing the cryptic: IndexError: list assignment index out of range. I eventually figured out that my code was trying to draw strings that were too long and would exceed the rightmost boundaries of the screen.

Short term suggestions: The precondition (that text length and positioning must not exceed the width of the display) needs to be communicated in the function documentation.

Long term suggestions: Modify draw_text to be more resilient to strings that are "too long" by either:

  • Throwing a custom exception message that clearly communicates what the user has done wrong (e.g. IndexError: Provided string length and/or position exceeds rightmost edge of Display)
  • Catch the error and deal with it, throwing a warning instead. This would require a design decision to be made - Will text that exceeds the screen boundary be trimmed off? Or will there be some way to wrap text into a newline instead?
@doglman doglman added documentation Improvements or additions to documentation enhancement New feature or request labels Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants