Ya he buscado entre muchas preguntas de otros usuarios, pero todavía no puedo entender por qué mi función no funciona correctamente. Escribí este código:
async function getFile(c, sourcePath, fileName, destPath) { return await new Promise((resolve, reject) => { c.cwd(sourcePath, function(err, currentDir) { // "c" is an instance of ftp module's class, "cwd" is one of its methods to change working directory err = new Error('trying to throw an error for testing the func'); if (err) reject(err); c.get(fileName, function(err, stream) { if (err) reject(err); stream.once('close', function() { resolve(); }); stream.pipe(fs.createWriteStream(destPath)); }); }); })); } (async function() { try { await getFile(c, '/path/to', 'file.xls', 'file.xls'); } catch (err) { throw err; } })(); El nodo devuelve un UnhandledPromiseRejectionWarning y no entiendo por qué. Devolví una promesa en la primera función y luego llamé a esa función en otra correctamente estructurada con la sintaxis async-await. ¿Qué está mal con mi código?