Skip to content

Solution#366

Open
TetianaSobolieva wants to merge 4 commits into
mate-academy:masterfrom
TetianaSobolieva:develop
Open

Solution#366
TetianaSobolieva wants to merge 4 commits into
mate-academy:masterfrom
TetianaSobolieva:develop

Conversation

@TetianaSobolieva

Copy link
Copy Markdown

No description provided.

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Summary

Your implementation handles all the core file-moving functionality correctly—detecting directory destinations with trailing /, moving files into existing directories, renaming when the destination doesn't exist, and validating source files. However, there's a critical issue with error handling: all error conditions use console.error() with return instead of throwing exceptions. The task specification explicitly requires that "an error must be thrown," so every error path (missing source file, destination directory doesn't exist, etc.) must use throw new Error() rather than console.error(). Critical fixes needed: - Replace all console.error() + return patterns with throw new Error('descriptive message') - Ensure the function throws rather than returns on validation failures - Update the catch block to either re-throw the original error or log it meaningfully before throwing Minor improvements: - Consider process.exit(1) after errors to signal failure to parent processes - The current catch (err) { console.error('error'); } discards useful debugging information Once you replace the error handling approach with proper exceptions, your implementation should fully meet the requirements. The core logic is solid—just needs the error handling approach adjusted to match the specification.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Summary

The implementation has critical issues with error handling that violate explicit task requirements. The task specification clearly states 'an error must be thrown' for invalid arguments (line 10), missing source file (line 19), and non-existent destination directory (line 41), yet all three still use console.error() + return instead. While file-moving functionality works correctly, these validation points must throw Error objects to meet the specification requirements. Additionally, the catch block discards useful error details by only logging 'error' without the actual error message. These issues must be fixed before approval.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread src/app.js
Comment on lines +8 to +11
/* eslint-disable no-console */
console.error('You need to pass two arguments!');

return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Replace console.error() + return with throw new Error() - the task specification requires 'an error must be thrown' for invalid arguments.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

the test will crash, I cant do this

Comment thread src/app.js
Comment on lines +19 to +24
if (!fs.existsSync(src) || !fs.statSync(src).isFile()) {
// throw new Error('Please check if the file you want to transfer exists!');

console.error('Please check if the file you want to transfer exists!');

return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Replace console.error() + return with throw new Error() - the task requires 'an error must be thrown' when source file doesn't exist. The correct throw statement is commented out on line 20.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

the test will crash, I cant do this

Comment thread src/app.js
Comment on lines +48 to +53

if (!fs.existsSync(parentDir)) {
// throw new Error('Destination directory does not exist!');
console.error('Destination directory does not exist!');

return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Replace console.error() + return with throw new Error() - the task explicitly requires throwing an error when destination directory doesn't exist. The correct throw statement is commented out on line 50.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

the test will crash, I cant do this

Comment thread src/app.js Outdated
Comment on lines +56 to +59
try {
fs.renameSync(src, finalPath);
} catch (err) {
console.error('error');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The catch block discards useful debugging information by only logging 'error'. Consider logging the actual error: console.error('Error moving file:', err.message) or re-throwing after logging.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

ok

Comment thread src/app.js
Comment on lines +56 to +60
try {
fs.renameSync(src, finalPath);
} catch (err) {
console.error('error');
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

After throwing errors (or catching them), consider adding process.exit(1) to signal failure to parent processes, as the app currently exits with success code 0 even on errors.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

ok

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Summary

This is an educational override to help you continue learning. Your core file-moving functionality works correctly for all specified scenarios, which is great! However, there are 4 critical error-handling issues that must be addressed to meet the task requirements: lines 13-15, 22-25, 33-35, and 48-50 all use console.error() + return instead of throw new Error(). The task explicitly requires throwing errors in these validation cases. You'll notice there's already commented-out throw new Error() code in several places - that's the correct approach you should uncomment or replicate. Once you replace all console.error() + return patterns with proper throw new Error() statements, your implementation will fully meet the specification. Keep up the good work on the functional aspects!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

Comment thread src/app.js
Comment on lines +31 to +34
if (destIsDir) {
if (!fs.existsSync(dest) || !fs.statSync(dest).isDirectory()) {
// throw new Error('Destination must be an existing directory!');
console.error('Destination must be an existing directory!');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This should throw an Error instead of using console.error() + return. The task explicitly requires 'an error is thrown' when a destination directory (specified with trailing /) does not exist.

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