-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
new sol #148
base: master
Are you sure you want to change the base?
new sol #148
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job, but small change needed
src/app.js
Outdated
throw new Error(err); | ||
} | ||
|
||
fs.rename(sourceAbsolutePath, finalDestination); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fs.rename is an asynchronous operation and needs to be awaited, or else errors may go unhandled and operations may not complete in the expected order.
src/app.js
Outdated
|
||
fs.rename(sourceAbsolutePath, finalDestination); | ||
} catch (err) { | ||
throw new Error(err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are throwing a new error but not adding any additional context. Consider adding a custom error message to provide more information about what went wrong.
src/app.js
Outdated
try { | ||
await fs.access(destinationDirectory); | ||
} catch (err) { | ||
throw new Error(err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are throwing a new error but not adding any additional context. Consider adding a custom error message to provide more information about what went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/app.js
Outdated
try { | ||
await fs.access(destinationDirectory); | ||
} catch (err) { | ||
throw new Error(`Destination directory does not exist: ${destinationDirectory}`); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider avoiding try catch
nesting
src/app.js
Outdated
const destinationAbsolutePath = path.resolve(destination); | ||
|
||
try { | ||
if (!(await fileExists(sourceAbsolutePath))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like fileExists function is redundant
if (!(await fileExists(sourceAbsolutePath))) { | |
if (!(await fs.access(filePath))) { |
src/app.js
Outdated
const fs = require('fs').promises; | ||
const path = require('path'); | ||
|
||
const fileExists = async (filePath) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is not used anywhere, so please remove it
No description provided.