Skip to content

add task solution#340

Open
MrZefirchk wants to merge 1 commit intomate-academy:masterfrom
MrZefirchk:develop
Open

add task solution#340
MrZefirchk wants to merge 1 commit intomate-academy:masterfrom
MrZefirchk:develop

Conversation

@MrZefirchk
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

Good work on the core logic for moving and renaming files! However, I'm requesting changes to address a critical error handling issue that causes the application to crash.

In src/app.js, the call to await setDestinationPath(...) is not wrapped in a try...catch block. When an invalid destination is provided (like a directory that doesn't exist), this function throws an error that isn't caught, leading to an unhandled promise rejection that crashes the program. Please ensure all asynchronous operations that can fail are properly handled.

Additionally, the try...catch block within setDestinationPath (around line 20) catches a specific error only to throw a more generic one. It would be more helpful to provide a more descriptive error message that explains why the path is invalid (e.g., 'Destination directory does not exist').


✨ 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 +18 to +28
try {
const destinationStat = await fs.stat(destination);

if (!destinationStat.isDirectory()) {
throw new Error('Destination is not a directory');
}

destinationPath = path.join(destination, path.basename(source));
} catch (error) {
throw new Error('Destination path is invalid');
}

Choose a reason for hiding this comment

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

This try...catch block has a logic issue. The throw on line 22 is immediately caught on line 26. This causes a specific error ('Destination is not a directory') to be replaced by a more generic one ('Destination path is invalid'). Consider restructuring this to handle path existence and type checks separately to provide more descriptive error messages.

return;
}

const destinationPath = await setDestinationPath(destination, absoluteSource);

Choose a reason for hiding this comment

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

The setDestinationPath function can throw an error (for example, when a destination directory with a trailing slash doesn't exist). This call is not wrapped in a try...catch block, which will lead to an unhandled promise rejection and cause the program to crash. You should handle potential errors from this function call, just like you do for validateSource and fs.rename.

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