Develop#361
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
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:
- 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 afs.statSync(source)call and ensurestats.isFile()is true; if not, throw anErrorexplaining that only regular files are supported. - 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 withconsole.errorandreturn. Replace those branches withthrow new Error('Destination directory does not exist: ' + destPath)(or similar), so that incorrect paths fail as specified. - Inside the
stats && stats.isDirectory()branch, you already knownewFileexists and is a directory, but the code then checksparentDir = 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 callfs.renameSyncon it.
Minor improvements (optional but helpful):
- Consider standardizing your error messages and behavior (always throwing for invalid paths instead of mixing
console.errorandthrow) 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
| if (!fs.existsSync(file)) { | ||
| console.error(`${file} doesn't exist`); | ||
|
|
||
| return; |
There was a problem hiding this comment.
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.
| 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); |
There was a problem hiding this comment.
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).
|
@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
left a comment
There was a problem hiding this comment.
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
| if (!srcStats.isFile()) { | ||
| console.error(`${file} must be a File`); | ||
| // throw new Error(`${file} must be a File`); | ||
|
|
||
| return; |
There was a problem hiding this comment.
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).
| if (newFile.endsWith('/')) { | ||
| if (!destExists) { | ||
| console.error(`${newFile} doesn't exist`); | ||
| // throw new Error(`${newFile} doesn't exist`); | ||
|
|
||
| return; |
There was a problem hiding this comment.
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.
| if (!fs.existsSync(parentDir)) { | ||
| console.error(`Invalid destination path: ${newFile}`); | ||
| // throw new Error(`Invalid destination path: ${newFile}`); | ||
|
|
||
| return; |
There was a problem hiding this comment.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
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
| if (!srcStats.isFile()) { | ||
| console.error(`${file} must be a File`); | ||
| // throw new Error(`${file} must be a File`); | ||
|
|
||
| return; |
There was a problem hiding this comment.
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.
| if (!destExists) { | ||
| console.error(`${newFile} doesn't exist`); | ||
| // throw new Error(`${newFile} doesn't exist`); | ||
|
|
||
| return; |
There was a problem hiding this comment.
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).
| if (!fs.existsSync(parentDir)) { | ||
| console.error(`Invalid destination path: ${newFile}`); | ||
| // throw new Error(`Invalid destination path: ${newFile}`); | ||
|
|
||
| return; |
There was a problem hiding this comment.
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.
No description provided.