Skip to content

fix an issue where some errors were ignored, and when the provided program did not perform any IO to show. #900

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 1 commit into from
Jun 19, 2025

Conversation

HikariNee
Copy link
Contributor

@HikariNee HikariNee commented Jun 18, 2025

Description

fix an issue where some errors were ignored, and when the provided program did not perform any IO to show.

Guidelines

  • My code follows the style guidelines of this project (formatted with Ruff)

  • I have performed a self-review of my own code

  • I have commented my code, particularly in hard-to-understand areas

  • I have made corresponding changes to the documentation if needed

  • My changes generate no new warnings

  • I have tested this change

  • Any dependent changes have been merged and published in downstream modules

  • I have added all appropriate labels to this PR

  • [Y] I have followed all of these guidelines.

How Has This Been Tested? (if applicable)

Tux dev server.

Please describe how you tested your code. e.g describe what commands you ran, what arguments, and any config stuff (if applicable)

NA

Screenshots (if applicable)

NA

Please add screenshots to help explain your changes.

Additional Information

NA

Summary by Sourcery

Include program errors in the output embed and display a default message when there's no program output.

Bug Fixes:

  • Append program_error to the output embed to prevent silent failures.
  • Show 'no result to show.' when the executed program produces no output.

Copy link
Contributor

sourcery-ai bot commented Jun 18, 2025

Reviewer's Guide

Adds handling for runtime program errors that were previously ignored and ensures a placeholder message is displayed when no output is produced by updating the execution flow and result embed formatting.

Sequence diagram for improved error and output handling in code execution

sequenceDiagram
    participant User as actor User
    participant Bot as Bot
    participant RunCog as RunCog
    participant CompilerService as CompilerService

    User->>Bot: Submit code to run
    Bot->>RunCog: _execute(compiler, code, options)
    RunCog->>CompilerService: Execute code
    CompilerService-->>RunCog: {compiler_error, program_error, program_output}
    alt compiler_error exists and compiler != nim
        RunCog->>RunCog: Append compiler_error to output_parts
    end
    alt program_error exists
        RunCog->>RunCog: Append program_error to output_parts
    end
    alt program_output exists
        RunCog->>RunCog: Append program_output to output_parts
    end
    RunCog->>RunCog: Join output_parts as output
    RunCog->>RunCog: _create_result_embed(language, output, service)
    RunCog-->>Bot: Embed with output or 'no result to show.'
    Bot-->>User: Display result embed
Loading

Class diagram for updated RunCog error and output handling

classDiagram
    class RunCog {
        ...
        async _execute(compiler, code, options) -> str | None
        async _create_result_embed(language, output, service) -> Embed
    }
    RunCog : +_execute() now appends program_error if present
    RunCog : +_create_result_embed() now shows 'no result to show.' if output is empty
Loading

File-Level Changes

Change Details Files
Handle program errors in the execution output
  • Introduced a check for program_error in the execution result
  • Appended the program error message to output_parts when present
tux/cogs/utility/run.py
Provide default message when no program output is produced
  • Refactored the embed description assignment into a multi-line f-string
  • Used a conditional inline expression to display 'no result to show.' when output is empty
tux/cogs/utility/run.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @HikariNee - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

description = f"-# Service provided by {service_link}\n```{language}\n{output}\n```"

description = (
f"-# Service provided by {service_link}\n```{language}\n{output if output else 'no result to show.'}\n```"
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (code-quality): Replace if-expression with or (or-if-exp-identity)

Suggested change
f"-# Service provided by {service_link}\n```{language}\n{output if output else 'no result to show.'}\n```"
f"-# Service provided by {service_link}\n```{language}\n{output or 'no result to show.'}\n```"


ExplanationHere we find ourselves setting a value if it evaluates to True, and otherwise
using a default.

The 'After' case is a bit easier to read and avoids the duplication of
input_currency.

It works because the left-hand side is evaluated first. If it evaluates to
true then currency will be set to this and the right-hand side will not be
evaluated. If it evaluates to false the right-hand side will be evaluated and
currency will be set to DEFAULT_CURRENCY.

Copy link

codecov bot commented Jun 18, 2025

Codecov Report

Attention: Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

Project coverage is 8.87%. Comparing base (80bd892) to head (ce691c1).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
tux/cogs/utility/run.py 0.00% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##            main    #900      +/-   ##
========================================
+ Coverage   8.77%   8.87%   +0.09%     
========================================
  Files        121     121              
  Lines      10187   10189       +2     
  Branches    1235    1236       +1     
========================================
+ Hits         894     904      +10     
+ Misses      9229    9219      -10     
- Partials      64      66       +2     
Flag Coverage Δ *Carryforward flag
database 0.30% <ø> (+<0.01%) ⬆️ Carriedforward from 80bd892
integration 5.95% <0.00%> (-0.01%) ⬇️
unit 6.41% <0.00%> (-0.01%) ⬇️

*This pull request uses carry forward flags. Click here to find out more.

Components Coverage Δ
Core Bot Infrastructure 16.45% <ø> (ø)
Database Layer 0.00% <ø> (ø)
Bot Commands & Features 0.00% <0.00%> (ø)
Event & Error Handling ∅ <ø> (∅)
Utilities & Helpers ∅ <ø> (∅)
User Interface Components 0.00% <ø> (ø)
CLI Interface ∅ <ø> (∅)
External Service Wrappers ∅ <ø> (∅)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kzndotsh kzndotsh merged commit 748791b into allthingslinux:main Jun 19, 2025
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants