anzip icon indicating copy to clipboard operation
anzip copied to clipboard

bug: Uncaught promise error while using entryHandler

Open jscti opened this issue 4 years ago • 2 comments

Hi there, a little bug on your lib :

Description

Throwing an error in entryHandler result on an UnhandledPromiseRejectionWarning + impossibility to catch it

Expected behaviour

Should forward error normally

Actual behaviour

Swallow error

Steps to reproduce

const entryHandler = async entry => {
        try {
            // unziping file to location
            await entry.saveTo(outputPath);

            return false;
        } catch (err) {
            // HERE => UnhandledPromiseRejectionWarning:
            throw new Error(`Error while unziping file "${entry.name}" : ${err}`);
        }
    };

try {
        await anzip(file, {
            pattern: /.*/,
            entryHandler,
            disableSave: true,
            disableOutput: true
        });
    } catch (err) {
        // HERE => should be able to catch the entryHandler error here
        throw new Error(`Error handling "${file}" : ${err}`);
    }

Environnement

Node version 14.7.0 Windows 10

Thanks :)

jscti avatar Feb 03 '21 14:02 jscti

And more than that, entryHandle seems not to be "awaited" correctly :

console.log('start');
let count = 0;
const entryHandler = async entry => {
        try {
            // unziping file to location
            await entry.saveTo(outputPath);

            count++;
            console.log('count', count);

            return false;
        } catch (err) {
            // HERE => UnhandledPromiseRejectionWarning:
            throw new Error(`Error while unziping file "${entry.name}" : ${err}`);
        }
    };

try {
        await anzip(file, {
            pattern: /.*/,
            entryHandler,
            disableSave: true,
            disableOutput: true
        });

        console.log('finish');
    } catch (err) {
        // HERE => should be able to catch the entryHandler error here
        throw new Error(`Error handling "${file}" : ${err}`);
    }

will output :

start
count 1
count 2
finish
count 3

which is not correct

jscti avatar Feb 12 '21 17:02 jscti

Thanks @jscti I will investigate.

mikbry avatar Feb 12 '21 17:02 mikbry