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

Fix for the paginator raising IndexError when provided with an empty object to paginate #247

Merged
merged 3 commits into from Jan 3, 2019

Conversation

Projects
None yet
3 participants
@SebastiaanZ
Copy link
Member

SebastiaanZ commented Jan 3, 2019

Currently, both the LinePaginator and ImagePaginator will raise an unanticipated exception when called with an empty object to paginate. See #246. One way this may happen is if the bot command !otname list is ran, but no names were added to the name list yet:

otname_list_before_example

After discussing this with @scragly and @tagptroll1 in the contrib channel, I'm proposing a two-folded fix for this:

  1. Send an empty embed with "(nothing to display)" if the __init__ kwarq exception_on_empty_embed = False. This is the default.

LinePaginator:
otname_list_example

ImagePaginator:
imagepaginator_noimagestodisplay

  1. Raise EmptyPaginatorEmbed exception when exception_on_empty_embed = True. This allows the function/command calling the paginator to handle it in some other way than an empty embed.

!internal eval codes to invoke the fix:

# LinePaginator exception_on_empty_embed=False
!internal eval
from bot.pagination import LinePaginator
from discord import Colour, Embed
embed = Embed(
    title=f"Known off-topic names (0 total)",
    colour=Colour.blue()
)
await LinePaginator.paginate([], ctx, embed, max_size=400, empty=False, exception_on_empty_embed=False)

# LinePaginator exception_on_empty_embed=True
!internal eval
from bot.pagination import LinePaginator
from discord import Colour, Embed
embed = Embed(
    title=f"Known off-topic names (0 total)",
    colour=Colour.blue()
)
await LinePaginator.paginate([], ctx, embed, max_size=400, empty=False, exception_on_empty_embed=True)

# ImagePaginator exception_on_empty_embed=False
!internal eval
from bot.pagination import ImagePaginator
from discord import Colour, Embed
embed = Embed(
    title=f"Ves Zappa's Selfie Album (0 total)",
    colour=Colour.blue()
)
await ImagePaginator.paginate([], ctx, embed, exception_on_empty_embed=False)

# ImagePaginator exception_on_empty_embed=True
!internal eval
from bot.pagination import LinePaginator
from discord import Colour, Embed
embed = Embed(
    title=f"Ves Zappa's Selfie Album (0 total)",
    colour=Colour.blue()
)
await ImagePaginator.paginate([], ctx, embed, exception_on_empty_embed=True)
@tagptroll1
Copy link
Contributor

tagptroll1 left a comment

Clear and useful

@LordHemlock
Copy link
Contributor

LordHemlock left a comment

Does what it says on the tin, and won't take extra work to implement it in other places. Well done.

@SebastiaanZ SebastiaanZ merged commit 8144c8a into master Jan 3, 2019

@SebastiaanZ SebastiaanZ deleted the fix-paginator-indexerror branch Jan 3, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment