Unhanded rejections and Promise constructor anti-patterns in FTP Driver
Frondor opened this issue · comments
Promise constructor anti-pattern can be noticed in these lines (more info):
https://github.com/Slynova-Org/node-flydrive/blob/7577b1bccce3dd6b8ee39faeda29c55e6ac8f6b6/src/Drivers/FTP.js#L97
https://github.com/Slynova-Org/node-flydrive/blob/7577b1bccce3dd6b8ee39faeda29c55e6ac8f6b6/src/Drivers/FTP.js#L141
Also, some tests are failing with different ftp servers (the one commented in the docker-compose
file at #54 ). I can't really debug the issue, but looks like some exceptions are not being handled. Like connection errors, closed connections and finalized connections. I think the driver should have a policy for that kind of events, and throw a proper exception. But I don't have that much idea about FTP sadly. (who consumes FTP servers in node apps anyway? 🤣 )
FTP Driver
1. move file
(node:32) UnhandledPromiseRejectionWarning: Error: 550 Rename/move failure
at Ftp.parse (/home/node/app/node_modules/jsftp/lib/jsftp.js:223:11)
at Ftp.parseResponse (/home/node/app/node_modules/jsftp/lib/jsftp.js:146:8)
at Stream.pipeline.on.data (/home/node/app/node_modules/jsftp/lib/jsftp.js:112:10)
at emitOne (events.js:116:13)
at Stream.emit (events.js:211:7)
at ResponseParser.reemit (/home/node/app/node_modules/duplexer/index.js:70:25)
at emitOne (events.js:116:13)
at ResponseParser.emit (events.js:211:7)
at readableAddChunk (/home/node/app/node_modules/readable-stream/lib/_stream_readable.js:195:16)
at ResponseParser.Readable.push (/home/node/app/node_modules/readable-stream/lib/_stream_readable.js:162:10)
(node:32) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:32) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
As far as I know, the server is returning a 550 Rename/move failure
for move file
test case of the FTP Driver, and looks like it isn't properly handling the error.
This may have something to do with how promises are being handled:
https://stackoverflow.com/questions/33445415/javascript-promises-reject-vs-throw
https://stackoverflow.com/questions/43036229/is-it-an-anti-pattern-to-use-async-await-inside-of-a-new-promise-constructor
You can test it by cloning my fork, and running the tests as described in #54
Hey @Frondor! 👋
I believe this driver need some loves.
I'll probably rewrite it since I'm not the one who did it at first glance.
Thanks for your investigation and your time, really appreciated!
Anytime mate!
FTP driver will be removed for the moment in the next version.
I'll see if I add it again as official driver or not.