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

error not caught when using async api to extract files #103

Open
WanGe2000 opened this issue Sep 6, 2023 · 5 comments · May be fixed by #104
Open

error not caught when using async api to extract files #103

WanGe2000 opened this issue Sep 6, 2023 · 5 comments · May be fixed by #104

Comments

@WanGe2000
Copy link

`
const StreamZip = require("node-stream-zip");
async function test() {
const zip = new StreamZip.async({
file: "C:\Users\Administrator\AppData\Roaming\xxxx\mods\443.zip",
});
try {
await zip.extract(null, "G:\Monster Hunter");
} catch (error) {
console.log(error);
}
console.log("-----");
}
test()

`

@WanGe2000 WanGe2000 changed the title try catch not working when using async api to extract files error not caught when using async api to extract files Sep 6, 2023
@DiscoNova
Copy link
Contributor

DiscoNova commented Sep 6, 2023

Hmm... are you sure it isn't working as expected? I see two problems with the provided sample; first you're executing test() synchronously and second, the filename has invalid hexadecimal escape sequence (you need to be really careful with backslashes on string literals; \xxxx seems to be the culprit of this)

When I modify the test slightly;

const StreamZip = require("node-stream-zip");
async function test() {
  try {
    // I'll do this inside the try-block to catch issues with opening the file too...
    const zip = new StreamZip.async({
      file: "443.zip" // for testing, bringing the file into current working directory
    });
    await zip.extract(null, "whatever");
  } catch (error) {
    console.error(error);
    throw error; // So we can catch this outside of the function, too...
  }
  console.log("-----");
}

test()
  .then(() => { console.done("File extracted?"); })
  .catch((e) => { console.error("Problem?", e); })
  .finally(() => { console.log("DONE!"); });

...it seems to work just as I would expect it to. Have I missed something?

Edit: Grantedly, the file I tested this with was an empty file, so results might differ when using an actual zip-file...

@WanGe2000
Copy link
Author

Thank you for your reply. You can try creating a new 5M disk and then extract a file larger than 5M using the extract api. You will receive an error like this
Error: ENOSPC: no space left on device, write Emitted 'error' event on WriteStream instance at: at WriteStream.onerror (_stream_readable.js:758:14) at WriteStream.emit (events.js:314:20) at emitErrorNT (internal/streams/destroy.js:106:8) at emitErrorCloseNT (internal/streams/destroy.js:74:3) at processTicksAndRejections (internal/process/task_queues.js:80:21) { errno: -4055, code: 'ENOSPC', syscall: 'write'}
but the error is not caught by try catch.

@WanGe2000
Copy link
Author

After testing, I found that the callback api also has this issues

 const zip = new StreamZip({
      file: "big.zip" // assume the big.zip is 50M
 });
zip.on('ready', () => {
    const outputPath = 'whatever' // assume the outputPath only left 10M space 
    zip.extract(null, outputPath , (err, count) => { 
        console.log(err ? 'Extract error' : `Extracted ${count} entries`);
        zip.close();
    });
});

WanGe2000 added a commit to WanGe2000/node-stream-zip that referenced this issue Sep 7, 2023
@WanGe2000 WanGe2000 linked a pull request Sep 7, 2023 that will close this issue
@Otaku-gsf
Copy link

same issue

1 similar comment
@boriborm
Copy link

same issue

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

Successfully merging a pull request may close this issue.

4 participants