Skip to content

fix(error): improve error messages#13

Merged
Pawank06 merged 2 commits intomainfrom
feature/cd-builtin-error
Jan 7, 2026
Merged

fix(error): improve error messages#13
Pawank06 merged 2 commits intomainfrom
feature/cd-builtin-error

Conversation

@Pawank06
Copy link
Owner

@Pawank06 Pawank06 commented Jan 7, 2026

summary

  • improve clarity of error messages shown to the user

notes

  • no functional behavior changes
  • focuses on better user feedback

fixes #12

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced error reporting for the cd command with improved distinction between non-existent paths and non-directory paths. Error messages now include the full user input and underlying system errors for better diagnostics and troubleshooting.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 7, 2026

📝 Walkthrough

Walkthrough

Sequentializes absolute-path cd validation: first checks existence, then directory-ness, then attempts to set the current directory. Error messages now use the original input path for "No such file or directory" and "Not a directory", and include the OS error when set_current_dir fails.

Changes

Cohort / File(s) Summary
CD command error handling
src/main.rs
Replace combined existence+dir check with three branches: (1) not exists -> prints "No such file or directory" using full input; (2) exists but not dir -> prints "Not a directory" using full input; (3) exists and dir -> call set_current_dir(full_path) and on failure print underlying OS error with path.display()

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I hopped through paths both near and far,
Found missing roots and rocks that mar.
I call them out with honest cheer,
And show the error loud and clear—
A tidy shell, a happier hare. 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: improving error messages in the cd command implementation for better user feedback.
Linked Issues check ✅ Passed All coding objectives from issue #12 are met: error messages for non-existent/non-directory paths, typo correction, and accurate error messages for set_current_dir failures.
Out of Scope Changes check ✅ Passed All changes in src/main.rs are directly related to addressing the three requirements in issue #12 for improving cd command error handling.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fc363a4 and 99334c2.

📒 Files selected for processing (1)
  • src/main.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main.rs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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: 1

🤖 Fix all issues with AI agents
In @src/main.rs:
- Around line 91-99: The conditional checks are inverted and use a non-existent
method; change the first check to if !path.exists() to report "No such file or
directory", replace path.dir() with path.is_dir() to test directoryness, and
send all error messages to stderr by using eprintln! instead of println!
(including the env::set_current_dir error message that currently prints
path.display() and the error), leaving the successful
env::set_current_dir(full_path) branch as-is.
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 568d75a and fc363a4.

📒 Files selected for processing (1)
  • src/main.rs
🧰 Additional context used
🪛 GitHub Actions: Rust
src/main.rs

[error] 93-93: no method named dir found for &std::path::Path in the current scope. There is a method is_dir with a similar purpose.


[error] 93-93: could not compile rshell (bin "rshell") due to 1 previous error

src/main.rs Outdated
Comment on lines 91 to 99
if path.exists() {
println!("cd: {}: No such file or directory", full_path);
} else if !path.dir() {
println!("cd: {}: Not a directory", full_path);
} else {
if let Err(e) = env::set_current_dir(full_path) {
println!("cd: {} {}", path.display(), e);
}
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Fix inverted logic and compilation error.

The condition logic is backwards and there's a method name error:

  1. Critical logic error (line 91): The condition if path.exists() will print "No such file or directory" when the path EXISTS, which is contradictory. It should be if !path.exists().

  2. Critical compilation error (line 93): path.dir() doesn't exist. The correct method is path.is_dir() (as shown in the pipeline failure).

  3. Error output location: Error messages should use eprintln! instead of println! to write to stderr rather than stdout, following standard Unix conventions.

🔧 Proposed fix
                    let path = Path::new(&full_path);
-                    if path.exists() {
-                        println!("cd: {}: No such file or directory", full_path);
-                    } else if !path.dir() {
-                        println!("cd: {}: Not a directory", full_path);
+                    if !path.exists() {
+                        eprintln!("cd: {}: No such file or directory", full_path);
+                    } else if !path.is_dir() {
+                        eprintln!("cd: {}: Not a directory", full_path);
                    } else {
                        if let Err(e) = env::set_current_dir(full_path) {
-                            println!("cd: {} {}", path.display(), e);
+                            eprintln!("cd: {} {}", path.display(), e);
                        }
                    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if path.exists() {
println!("cd: {}: No such file or directory", full_path);
} else if !path.dir() {
println!("cd: {}: Not a directory", full_path);
} else {
if let Err(e) = env::set_current_dir(full_path) {
println!("cd: {} {}", path.display(), e);
}
}
if !path.exists() {
eprintln!("cd: {}: No such file or directory", full_path);
} else if !path.is_dir() {
eprintln!("cd: {}: Not a directory", full_path);
} else {
if let Err(e) = env::set_current_dir(full_path) {
eprintln!("cd: {} {}", path.display(), e);
}
}
🧰 Tools
🪛 GitHub Actions: Rust

[error] 93-93: no method named dir found for &std::path::Path in the current scope. There is a method is_dir with a similar purpose.


[error] 93-93: could not compile rshell (bin "rshell") due to 1 previous error

🤖 Prompt for AI Agents
In @src/main.rs around lines 91 - 99, The conditional checks are inverted and
use a non-existent method; change the first check to if !path.exists() to report
"No such file or directory", replace path.dir() with path.is_dir() to test
directoryness, and send all error messages to stderr by using eprintln! instead
of println! (including the env::set_current_dir error message that currently
prints path.display() and the error), leaving the successful
env::set_current_dir(full_path) branch as-is.

@Pawank06 Pawank06 merged commit 35d5433 into main Jan 7, 2026
2 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.

Improve error handling and fix typo in cd command implementation

1 participant