Skip to content
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

bug: Uncaught promise error while using entryHandler #23

Open
jscti opened this issue Feb 3, 2021 · 2 comments
Open

bug: Uncaught promise error while using entryHandler #23

jscti opened this issue Feb 3, 2021 · 2 comments
Assignees

Comments

@jscti
Copy link

jscti commented Feb 3, 2021

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
Copy link
Author

jscti commented Feb 12, 2021

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

@mikbry
Copy link
Owner

mikbry commented Feb 12, 2021

Thanks @jscti I will investigate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants