Skip to content

Develop#361

Open
dmytro-halieba wants to merge 7 commits into
mate-academy:masterfrom
dmytro-halieba:develop
Open

Develop#361
dmytro-halieba wants to merge 7 commits into
mate-academy:masterfrom
dmytro-halieba:develop

Conversation

@dmytro-halieba

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

I am requesting changes because there are still a couple of requirement-level gaps in src/app.js that affect correctness of the tool.

Critical issues that must be fixed:

  1. The app is required to move only files, but the current code only checks that the source path exists and does not verify that it is a regular file. In the block where you validate the source path near the top of src/app.js, add a fs.statSync(source) call and ensure stats.isFile() is true; if not, throw an Error explaining that only regular files are supported.
  2. Where you handle destinations that must be existing directories (e.g. a path ending with / or when the target already exists and is a directory), the requirement says that a missing destination directory must result in a thrown error, but currently you log with console.error and return. Replace those branches with throw new Error('Destination directory does not exist: ' + destPath) (or similar), so that incorrect paths fail as specified.
  3. Inside the stats && stats.isDirectory() branch, you already know newFile exists and is a directory, but the code then checks parentDir = path.dirname(newFile) and complains that it does not exist. This check is misleading and unnecessary; you can remove the extra existence check and instead directly compute the final destination inside that directory and call fs.renameSync on it.

Minor improvements (optional but helpful):

  • Consider standardizing your error messages and behavior (always throwing for invalid paths instead of mixing console.error and throw) so callers see consistent failures.

Once you add the file-type check, throw errors for missing destination directories, and simplify the directory-branch logic, your implementation will align well with the mv-like behavior and the stated requirements.


✨ 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 +14 to +17
if (!fs.existsSync(file)) {
console.error(`${file} doesn't 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.

The code checks that the source path exists but does not verify that the source is a file (not a directory). The task requires the app to support only moving of files, so add a check such as fs.statSync(file).isFile() and error out if it's not a regular file.

Comment thread src/app.js
Comment on lines +39 to +47
if (stats && stats.isDirectory()) {
const newPath = path.join(newFile, fileName);

if (!fs.existsSync(parentDir)) {
console.error(`${newPath} doesn't exist`);

return;
}
fs.renameSync(file, newPath);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Inside the stats && stats.isDirectory() branch you check parentDir existence (path.dirname(newFile)) which is not the correct condition and is unnecessary because destExists is already true. This can produce misleading errors. Remove or replace this check with clearer logic (you already know newFile exists and is a directory, so you can directly compute the destination path and rename).

@dmytro-halieba

Copy link
Copy Markdown
Author

@mateacademy-ai-mentor tests expect me to use console.error. I CAN'T USE throw new Error because of the tests, be adviced

@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

I am requesting changes because some critical error-handling paths in src/app.js still log and return instead of throwing, which violates the task requirements and will cause tests that expect thrown errors to fail. In the branch where you call fs.statSync(file) and find that !stats.isFile() (source is not a regular file), you must replace console.error(...) + return with something like:

console.error('Source is not a regular file: ' + file);
throw new Error('Source is not a regular file: ' + file); // [CHECKLIST ITEM #11, #12]

Similarly, in the branch where newFile.endsWith('/') and the destination directory does not exist, you currently console.error and return—this must instead log and then throw new Error('Destination directory does not exist: ' + newFile); so that missing directories are treated as hard failures [CHECKLIST ITEM #3, #10, #13]. The same change is needed where you validate the parent directory of the destination path: after detecting that the parent directory does not exist, log the message and then throw an Error instead of returning. This pattern (console.error(...) followed by throw new Error(...)) addresses your concern about tests expecting console output while still meeting the explicit requirement that these conditions throw. Once these three branches throw appropriately, the rest of your move/rename logic (including handling existing destination directories and using fs.renameSync) looks solid, and your solution will align with the checklist; nice work on those parts so far.


✨ 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 +24 to +28
if (!srcStats.isFile()) {
console.error(`${file} must be a File`);
// throw new Error(`${file} must be a File`);

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.

You already call fs.statSync(file) and check isFile(), which is correct. However, this branch currently uses console.error and return. Per checklist items #11 and #12 you must throw an Error when the source is not a regular file. Replace the console.error/return with a thrown Error (you may log first then throw to keep test compatibility).

Comment thread src/app.js
Comment on lines +36 to +41
if (newFile.endsWith('/')) {
if (!destExists) {
console.error(`${newFile} doesn't exist`);
// throw new Error(`${newFile} doesn't 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.

When the destination ends with / you require that directory to exist — currently you console.error and return if it doesn't. Per checklist items #3, #10 and #13 this must throw an Error (for example: throw new Error('Destination directory does not exist: ' + newFile)). Consider logging then throwing if tests assert on console output.

Comment thread src/app.js
Comment on lines +59 to +63
if (!fs.existsSync(parentDir)) {
console.error(`Invalid destination path: ${newFile}`);
// throw new Error(`Invalid destination path: ${newFile}`);

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.

For an invalid parent directory you console.error and return. This case also requires a thrown Error (see checklist #3 and #10). Replace the console.error/return with a thrown Error (or console.error(...) followed by throw new Error(...) to preserve console output for tests).

@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

I am approving your solution as an educational override so you can continue progressing, even though there are still a few error-handling details to fix. You’ve correctly implemented the core mv-like behavior in src/app.js, including using fs.renameSync and handling both simple renames and moves into directories. The main remaining issues are all about error handling: in the branch where you check that the source is a regular file (the if (!srcStats.isFile()) logic in src/app.js), and in the branches handling a destination ending with / whose directory does not exist, and an invalid parent destination path, you currently console.error(...) and then return instead of logging and then throwing an Error so tests can observe the failure [CHECKLIST ITEM #3, #10, #11, #12, #13]. After each of those console.error(...) calls, you should add a throw new Error(...) with a clear, specific message about what went wrong (for example, that the source is not a regular file, that the destination directory with a trailing slash is missing, or that the parent destination path is invalid). As a minor improvement, you may also want to review your argument-count/usage branch to decide whether it should follow the same “log then throw” pattern for consistency, depending on the task requirements. Overall, your move/rename logic is solid; tightening these few error-handling paths will make your solution fully compliant and more robust, and you’re very close to a polished implementation.


✨ 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 +27 to +31
if (!srcStats.isFile()) {
console.error(`${file} must be a File`);
// throw new Error(`${file} must be a File`);

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.

When the source exists but is not a regular file you currently console.error(...) and return. Per the checklist you must both log and throw an error so tests can observe the failure. Replace the return with throw new Error('Source is not a regular file: ' + file) (or uncomment the existing commented throw) after the console.error.

Comment thread src/app.js
Comment on lines +40 to +44
if (!destExists) {
console.error(`${newFile} doesn't exist`);
// throw new Error(`${newFile} doesn't 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.

When newFile ends with / and the destination directory does not exist you currently console.error(...) and return. The requirement is to treat missing destination directories as hard failures. After the console.error you should throw new Error('Destination directory does not exist: ' + newFile) (instead of returning).

Comment thread src/app.js
Comment on lines +62 to +66
if (!fs.existsSync(parentDir)) {
console.error(`Invalid destination path: ${newFile}`);
// throw new Error(`Invalid destination path: ${newFile}`);

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.

When validating the parent directory of the destination you currently console.error(...) and return if it doesn't exist. According to the requirements this must log and then throw an Error (e.g. throw new Error('Invalid destination path: ' + newFile)) so callers/tests receive a thrown error.

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