Skip to content

The error messages should be more descriptive now #120

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

Conversation

Arpan-206
Copy link
Contributor

@Arpan-206 Arpan-206 commented Apr 12, 2025

Before:
Screenshot 2025-04-12 at 18 18 59

After:
Screenshot 2025-04-25 at 12 06 21

After (outdated):
Screenshot 2025-04-22 at 19 26 20

After (outdated, so disregard):
Screenshot 2025-04-12 at 18 18 52

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling and logging for shell output, providing clearer and more specific error messages when issues occur during shell execution.
  • Style
    • Updated error message wording for consistency and clarity in user-facing output.

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling for exit command scenarios, ensuring more accurate detection when a program fails to exit as expected.
    • Fixed off-by-one errors in shell output logging for more precise output tracking.
  • Tests

    • Added a new test case to verify shell behavior when the exit command is not properly handled.
    • Updated test fixtures to reflect changes in system utility paths and to cover new error scenarios.
  • Chores

    • Introduced new test scenario files, scripts, and configuration for enhanced test coverage and debugging.

Copy link

linear bot commented Apr 12, 2025

@Arpan-206 Arpan-206 requested a review from rohitpaulk April 12, 2025 17:20
Copy link

coderabbitai bot commented Apr 12, 2025

Walkthrough

This change introduces enhanced error handling in the testExit function to better recognize when a program fails to exit as expected, specifically by treating the ErrConditionNotMet error as a sign that the program is still running. It also adds a new test scenario (exit_error) with corresponding fixtures and configuration to verify this behavior. Additionally, test fixture outputs for certain bash scenarios are updated to reflect changes in system utility paths from /bin/ to /usr/bin/. Minor fixes were made to logging index boundaries in the shell asserter to correct off-by-one errors.

Changes

File(s) Change Summary
internal/stage4.go Updated testExit to handle ErrConditionNotMet as a non-exit condition, log remaining output, and return a consistent error message indicating the program is still running.
internal/stages_test.go Added a new test case "exit_error_fail" for the new exit error scenario, using the corresponding fixture and scenario.
internal/test_helpers/fixtures/bash/base/pass
internal/test_helpers/fixtures/bash/navigation/pass
Updated expected output for the type command in stage-7 to reflect new paths for cat, cp, and mkdir from /bin/ to /usr/bin/.
internal/test_helpers/fixtures/exit_error Added a new fixture file simulating a shell session where an invalid command and a failed exit are tested, with expected output and error logs.
internal/test_helpers/scenarios/exit_error/codecrafters.yml Added a new scenario configuration file enabling debug logging.
internal/test_helpers/scenarios/exit_error/main.py Added a new Python script implementing a basic shell loop that only exits on "exitt" and prints errors for other commands.
internal/test_helpers/scenarios/exit_error/your_shell.sh Added a new shell script to invoke the Python shell implementation for testing.
internal/logged_shell_asserter/logged_shell_asserter.go Fixed off-by-one errors in logging row indices to ensure correct logging of shell output rows and accurate tracking of last logged row index.

Sequence Diagram(s)

sequenceDiagram
    participant Tester
    participant ShellScript
    participant PythonShell

    Tester->>ShellScript: Run your_shell.sh
    ShellScript->>PythonShell: Execute main.py
    PythonShell->>Tester: Display prompt "$ "
    Tester->>PythonShell: Send command (e.g., invalid_apple_command)
    PythonShell->>Tester: Print "invalid_apple_command: command not found"
    PythonShell->>Tester: Display prompt "$ "
    Tester->>PythonShell: Send "exit 0"
    PythonShell->>Tester: Print "exit: command not found"
    PythonShell->>Tester: Display prompt "$ "
    Tester->>Tester: Detects program did not exit, logs error
Loading

Possibly related PRs

Suggested reviewers

  • rohitpaulk

Poem

A bunny hopped through code anew,
To catch the shell that wouldn’t bid adieu.
With error logs and fixtures bright,
It chased the bug far into the night.
Paths updated, tests in tow—
Now the exit’s clear, the prompt says “go!”
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 5892035 and 509220b.

📒 Files selected for processing (2)
  • internal/test_helpers/fixtures/bash/base/pass (2 hunks)
  • internal/test_helpers/fixtures/bash/navigation/pass (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/test_helpers/fixtures/bash/navigation/pass
  • internal/test_helpers/fixtures/bash/base/pass

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Arpan-206
Copy link
Contributor Author

lemme try fixing, pls hold off on review

@Arpan-206
Copy link
Contributor Author

ok now (I rebuilt some executables but didn't have all tools on my system)

@Arpan-206 Arpan-206 self-assigned this Apr 12, 2025
@rohitpaulk
Copy link
Member

@Arpan-206 the error message is still confusing. Why are we expecting a prompt to appear after running exit? And why are we printing program output in red? A user's program output should always just appear under your_program.

Copy link
Member

@rohitpaulk rohitpaulk left a comment

Choose a reason for hiding this comment

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

Needs more thought on how to make the message user friendly, as of now it's still confusing

@Arpan-206 Arpan-206 closed this Apr 20, 2025
@Arpan-206 Arpan-206 force-pushed the arpan/cc-1667-fix-incorrect-shell-tester-message-for-stage-pn5 branch from 0e6f4ac to aec290e Compare April 20, 2025 11:23
@Arpan-206 Arpan-206 reopened this Apr 20, 2025
@Arpan-206 Arpan-206 requested a review from rohitpaulk April 21, 2025 18:18
@Arpan-206 Arpan-206 marked this pull request as draft April 21, 2025 18:18
Copy link
Member

@rohitpaulk rohitpaulk left a comment

Choose a reason for hiding this comment

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

@Arpan-206 let's make it a point to update the description with newer screenshots - can't make sense of what the new error message is now. Secondly, let's add tests for this as mentioned in Linear - check stages_test.go for examples

@Arpan-206
Copy link
Contributor Author

Screenshot 2025-04-22 at 19 25 30 New SS, adding tests!

@Arpan-206 Arpan-206 force-pushed the arpan/cc-1667-fix-incorrect-shell-tester-message-for-stage-pn5 branch from 92d6455 to 2b2804c Compare April 22, 2025 19:20
@Arpan-206 Arpan-206 marked this pull request as ready for review April 22, 2025 20:04
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
internal/test_helpers/scenarios/exit_error/codecrafters.yml (1)

1-5: Fix YAML formatting issues

There are two minor formatting issues in this file:

  1. There are trailing spaces at the end of line 5
  2. There's no newline at the end of the file
# Set this to true if you want debug logs.
#
# These can be VERY verbose, so we suggest turning them off
# unless you really need them.
-debug: true 
+debug: true
+
🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 5-5: no new line character at the end of file

(new-line-at-end-of-file)


[error] 5-5: trailing spaces

(trailing-spaces)

internal/test_helpers/scenarios/exit_error/your_shell.sh (1)

8-8: Fix potential word splitting issue in command substitution

The $(dirname "$0") command substitution should be quoted to prevent word splitting if the path contains spaces.

-exec python3 $(dirname "$0")/main.py "$@" 
+exec python3 "$(dirname "$0")"/main.py "$@"
+

This change also adds a trailing newline at the end of the file.

🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 8-8: Quote this to prevent word splitting.

(SC2046)

internal/test_helpers/scenarios/exit_error/main.py (2)

12-12: Remove unused variable assignment

The args variable is assigned but never used in the code.

        command = input().strip()
        parts = command.split(" ")
        cmd = parts[0]
-        args = parts[1:]
+        # args = parts[1:]  # Uncomment when needed
🧰 Tools
🪛 Ruff (0.8.2)

12-12: Local variable args is assigned to but never used

Remove assignment to unused variable args

(F841)


21-22: Add newline at end of file

The file is missing a newline at the end.

if __name__ == "__main__":
-    main() 
+    main()
+
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 8f9e346 and c48b05a.

📒 Files selected for processing (8)
  • internal/stage4.go (2 hunks)
  • internal/stages_test.go (1 hunks)
  • internal/test_helpers/fixtures/bash/base/pass (1 hunks)
  • internal/test_helpers/fixtures/bash/navigation/pass (1 hunks)
  • internal/test_helpers/fixtures/exit_error (1 hunks)
  • internal/test_helpers/scenarios/exit_error/codecrafters.yml (1 hunks)
  • internal/test_helpers/scenarios/exit_error/main.py (1 hunks)
  • internal/test_helpers/scenarios/exit_error/your_shell.sh (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • internal/test_helpers/fixtures/bash/navigation/pass
  • internal/test_helpers/fixtures/bash/base/pass
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/stage4.go
🧰 Additional context used
🪛 Ruff (0.8.2)
internal/test_helpers/scenarios/exit_error/main.py

12-12: Local variable args is assigned to but never used

Remove assignment to unused variable args

(F841)

🪛 YAMLlint (1.35.1)
internal/test_helpers/scenarios/exit_error/codecrafters.yml

[error] 5-5: no new line character at the end of file

(new-line-at-end-of-file)


[error] 5-5: trailing spaces

(trailing-spaces)

🪛 Shellcheck (0.10.0)
internal/test_helpers/scenarios/exit_error/your_shell.sh

[warning] 8-8: Quote this to prevent word splitting.

(SC2046)

🔇 Additional comments (6)
internal/stages_test.go (1)

36-42: Well-structured test case for the new exit error scenario

The new test case is properly structured and follows the same pattern as other test cases. It correctly references the new scenario path and fixture output.

internal/test_helpers/scenarios/exit_error/main.py (1)

14-15:

✅ Verification successful

Verify intentional misspelling of "exitt" command

The code only recognizes "exitt" (with two 't's) instead of the standard "exit" command. This appears to be intentional for testing purposes, but please confirm this is the desired behavior.


🏁 Script executed:

#!/bin/bash
# Check if this behavior is consistent with other test scenarios in the codebase
grep -r "exit" --include="*.py" internal/test_helpers/scenarios/

Length of output: 217


Confirmed intentional misspelling in exit_error scenario
A recursive search for “exit” across all test scenarios only finds the exitt check and corresponding sys.exit(0) in internal/test_helpers/scenarios/exit_error/main.py. This appears deliberate to differentiate it from the normal “exit” command. No changes are needed.

internal/test_helpers/fixtures/exit_error (4)

1-2: LGTM: Debug mode enables better traceability.

Debug flag is properly set to true, which will help in troubleshooting this test scenario by providing more detailed logs.


3-7: LGTM: Test sequence correctly validates command not found behavior.

The test correctly verifies that an invalid command produces the expected "command not found" error message, which is a fundamental shell behavior.


8-10: Effectively captures the exit command failure.

This section effectively demonstrates the specific error case - where a shell incorrectly treats exit as an external command rather than a built-in shell directive. This is a crucial test case as implementing built-ins like exit is a fundamental requirement for a functioning shell.


11-12: Clear error messaging aligns with PR objectives.

The error message is now more descriptive and clearly communicates what went wrong (program should have exited but is still running). This directly addresses the PR objective of improving error message clarity.

@Arpan-206
Copy link
Contributor Author

Screenshot 2025-04-25 at 12 06 21

New error message.

@Arpan-206 Arpan-206 requested a review from rohitpaulk April 25, 2025 11:07
@@ -47,6 +48,9 @@ func testExit(stageHarness *test_case_harness.TestCaseHarness) error {
if !errors.Is(readErr, shell_executable.ErrProgramExited) {
if readErr == nil {
return fmt.Errorf("Expected program to exit with 0 exit code, program is still running.")
} else if errors.Is(readErr, condition_reader.ErrConditionNotMet) {
asserter.LogRemainingOutput()
Copy link
Member

Choose a reason for hiding this comment

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

@Arpan-206 thought we talked about this - we should be logging this no matter what, not only when a specific error type is found

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I thought I changed it back, lemme do that!

Copy link
Member

@rohitpaulk rohitpaulk left a comment

Choose a reason for hiding this comment

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

Added note: re logging remaining output

@Arpan-206 Arpan-206 requested a review from rohitpaulk April 29, 2025 09:32
Copy link
Member

@rohitpaulk rohitpaulk left a comment

Choose a reason for hiding this comment

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

Root cause not identified, and we shouldnt' need any err checks before logging remaining output

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
internal/logged_shell_asserter/logged_shell_asserter.go (1)

118-139: Consider adding debug logging for boundary errors

All these fixes address important off-by-one errors in row boundary calculations. Since these types of boundary errors can be subtle, consider adding some debug logging to help identify similar issues in the future.

func (a *LoggedShellAsserter) logRows(startRowIndex int, endRowIndex int) {
+	// Debug logging for boundary calculations (consider using a debug log level)
+	// a.Shell.GetLogger().Debugf("Logging rows from %d to %d (total rows: %d)", 
+	//                           startRowIndex, endRowIndex, len(a.Shell.GetScreenState()))
	for i := startRowIndex; i <= endRowIndex; i++ {
		rawRow := a.Shell.GetScreenState()[i]
		cleanedRow := virtual_terminal.BuildCleanedRow(rawRow)
		if len(cleanedRow) > 0 {
			a.Shell.LogOutput([]byte(cleanedRow))
		}
	}
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 1eb88c1 and 5892035.

📒 Files selected for processing (2)
  • internal/logged_shell_asserter/logged_shell_asserter.go (1 hunks)
  • internal/stage4.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/stage4.go
🔇 Additional comments (3)
internal/logged_shell_asserter/logged_shell_asserter.go (3)

118-121: Fixed off-by-one error in error row logging

The changes correctly adjust the row indices in the logAssertionError method. This ensures that all rows between the last logged row and the error row, as well as all rows after the error, are properly displayed in the logs.


124-129: Improved remaining output logging and tracking

These changes fix two important issues:

  1. Setting the proper end index for logging (using length-1 instead of length)
  2. Updating the lastLoggedRowIndex to correctly reflect the last row that was logged

This ensures that when logging remaining output, we accurately track which rows have already been displayed and avoid missing or duplicating rows in the logs.


131-132: Fixed loop condition to include the end row

Changed the loop condition from i < endRowIndex to i <= endRowIndex to ensure the row at the end index is also included in the logs. This correctly implements the expected behavior of the logRows method.

@Arpan-206 Arpan-206 requested a review from rohitpaulk April 29, 2025 19:59
@Arpan-206 Arpan-206 merged commit f8d9cbf into main Apr 30, 2025
6 checks passed
@Arpan-206 Arpan-206 deleted the arpan/cc-1667-fix-incorrect-shell-tester-message-for-stage-pn5 branch April 30, 2025 10:04
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