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

Eval output allows too many lines #2492

Closed
TizzySaurus opened this issue Mar 27, 2023 · 0 comments · Fixed by #3046
Closed

Eval output allows too many lines #2492

TizzySaurus opened this issue Mar 27, 2023 · 0 comments · Fixed by #3046
Assignees
Labels
a: frontend Related to output and formatting a: utility Related to utility commands: (bot, eval, extensions, jams, reminders, snekbox, utils) p: 2 - normal Normal Priority status: approved The issue has received a core developer's approval t: bug Something isn't working

Comments

@TizzySaurus
Copy link
Contributor

The Problem

The MAX_OUTPUT_BLOCK_LINES variable is set to a value of 10, which means under the current logic evals which output more than 10 lines, will be uploaded to the haste site (paste.pydis.com) and a message will be added to the eval output stating it was truncated.

However, since we currently update the lines variable to be lines[:max_lines+1], outputs of 11 lines (such as for x in range(11): print(x)) will be uploaded to the pastebin and still display all 11 lines (despite the limit being 10). This also means that the paste content is the same as what's sent to Discord as the eval content.

The code should be changed to instead change lines to lines[:max_lines]. This will also break the logic underneath (you've shortened so will never be more than max_lines) so the if statements will have to be swapped around.

Current Code

        if len(lines) > 1:
            if line_nums:
                lines = [f"{i:03d} | {line}" for i, line in enumerate(lines, 1)]
            lines = lines[:max_lines+1]  # Limiting to max+1 lines
            output = "\n".join(lines)

        if len(lines) > max_lines:
            truncated = True
            if len(output) >= max_chars:
                output = f"{output[:max_chars]}\n... (truncated - too long, too many lines)"
            else:
                output = f"{output}\n... (truncated - too many lines)"

Proposed Solution (approx.)

    if len(lines) > max_lines:
        truncated = True
        lines = lines[:max_lines]

    if len(lines) > 1:
        if line_nums:
            lines = [f"{i:03d} | {line}" for i, line in enumerate(lines, 1)]
        output = "\n".join(lines)
    
    if truncated:
        if len(output) > max_chars:
            output = f"{output[:max_chars]}\n... (truncated - too long, too many lines)"
        else:
            output = f"{output}\n... (truncated - too many lines)"

Notice that the proposed solution sets lines to lines[:max_lines] instead of lines[:max_lines + 1]. In reality the if truncated part can just be slotted into the pre-existing if truncated block

@TizzySaurus TizzySaurus added t: bug Something isn't working a: frontend Related to output and formatting p: 2 - normal Normal Priority a: utility Related to utility commands: (bot, eval, extensions, jams, reminders, snekbox, utils) labels Mar 27, 2023
@TizzySaurus TizzySaurus self-assigned this Mar 27, 2023
@mbaruh mbaruh added the status: approved The issue has received a core developer's approval label Mar 27, 2023
@vivekashok1221 vivekashok1221 linked a pull request May 12, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: frontend Related to output and formatting a: utility Related to utility commands: (bot, eval, extensions, jams, reminders, snekbox, utils) p: 2 - normal Normal Priority status: approved The issue has received a core developer's approval t: bug Something isn't working
Projects
None yet
3 participants