Skip to content

node_move-files_TetSh#335

Open
TetiankaSh wants to merge 3 commits intomate-academy:masterfrom
TetiankaSh:develop
Open

node_move-files_TetSh#335
TetiankaSh wants to merge 3 commits intomate-academy:masterfrom
TetiankaSh:develop

Conversation

@TetiankaSh
Copy link

No description provided.

Copy link

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

Choose a reason for hiding this comment

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

Review Summary

Great job implementing the logic for moving and renaming files! Your code correctly handles most scenarios. However, a couple of critical changes are needed to ensure the program is reliable and meets all requirements.

There are two main issues to address:

  1. The use of the asynchronous fs.rename function can cause the script to exit before the file move is complete, making the tool unreliable. To fix this, please use its synchronous counterpart, fs.renameSync(), which will guarantee the operation finishes before the program terminates.
  2. The requirements state that an error must be thrown if the destination directory doesn't exist. Your current implementation only logs a message to the console. Please change this to throw new Error(...) to correctly handle this case.

Once these are fixed, your solution will be in great shape!


✨ 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

src/app.js Outdated
Comment on lines 29 to 32
if (!targetExists && endsWithSlash) {
console.error('Destination directory does not exist');

return;

Choose a reason for hiding this comment

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

According to the requirements, an error must be thrown if the destination directory does not exist. This implementation only logs a message to the console and returns, which does not fulfill the requirement.

src/app.js Outdated
Comment on lines 46 to 50
fs.rename(oldFile, newFile, (err) => {
if (err) {
throw err;
}
});

Choose a reason for hiding this comment

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

Using the asynchronous fs.rename function here is problematic because the main script can finish executing before this operation completes. This might lead to the program terminating before the file is actually moved. Consider using its synchronous counterpart, fs.renameSync, to ensure the operation finishes before the script exits.

Copy link

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

Choose a reason for hiding this comment

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

Review Summary

Great progress on this! You're very close to a complete solution. However, a couple of changes are needed to meet the requirements.

  1. The synchronous fs.renameSync function does not accept a callback. It throws an error directly on failure, so you should remove the third argument (the callback function) from your call to fs.renameSync.
  2. One of the checks for a non-existent destination directory logs a message instead of throwing an error. The requirement is to throw an error in this case, so please change the console.log to throw new Error(...).

Once you've addressed these points, your code will be all set. Keep up the excellent work!


✨ 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 on lines +38 to +41
if (!fs.existsSync(targetFolder)) {
console.error('Directory does not exist');

return;

Choose a reason for hiding this comment

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

This check correctly identifies that the destination directory doesn't exist. However, the requirement is to throw an error in this case, not just log a message to the console. Please change this to throw new Error(...) to align with the requirements and the error handling on line 30.

Copy link
Author

Choose a reason for hiding this comment

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

If I change this to :
if (!fs.existsSync(targetFolder)) {
throw new Error('Directory does not exist');
}

the tests are failing and I can't commit it
so I kept it as it is, because the tests are passing only with this console.error option

src/app.js Outdated
Comment on lines 44 to 48
fs.renameSync(oldFile, newFile, (err) => {
if (err) {
throw err;
}
});

Choose a reason for hiding this comment

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

Great job switching to the synchronous fs.renameSync function! However, the synchronous version doesn't use a callback function like its asynchronous counterpart. It will throw an error directly if the operation fails, so you should remove the callback from this call.

Copy link

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

Choose a reason for hiding this comment

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

Review Summary

I am approving your solution as an educational override to help you progress, as there is one small adjustment still needed.

Excellent work addressing the previous feedback! You've correctly updated the fs.renameSync call and fixed one of the error-handling cases.

The final step is to address the requirement that an error must be thrown if the destination directory doesn't exist. Your code currently logs an error to the console in one place instead. In src/app.js, please change the final check for the destination folder to throw new Error('Directory does not exist'); instead of using console.error.

You're very close to a perfect solution!


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

Footnotes

  1. Rate AI review example

Comment on lines +38 to +41
if (!fs.existsSync(targetFolder)) {
console.error('Directory does not exist');

return;

Choose a reason for hiding this comment

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

The requirements state that an error must be thrown if the destination directory doesn't exist. This implementation logs an error to the console instead. Please change this to throw new Error('Directory does not exist'); to align with the requirements.

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