FredKSchott / rollup-plugin-polyfill-node

A modern Node.js polyfill for your Rollup bundle.
Other
177 stars 57 forks source link

Zlib binding of error code does not seem to work properly #70

Open jbghoul opened 1 year ago

jbghoul commented 1 year ago

Using Buffer and zlib from this rollup-plugin-polyfill-node package

In zlib.js polyfill, when an error occurs, zlib is supposed to emit and error. Related code below:

this._binding.onerror = function(message, errno) {
    // there is no way to cleanly recover.
    // continuing only obscures problems.
    self._binding = null;
    self._hadError = true;

    var error = new Error(message);
    error.errno = errno;
    error.code = binding.codes[errno];
    self.emit('error', error);
  };

But it seems that binding.codes is undefined, and an uncaught TypeError is thrown instead:

zlib.inflateRawSync(Buffer.from(""))

index.js:5 Uncaught TypeError: Cannot read properties of undefined (reading '-5')
    at Zlib._binding.onerror (index.js:5:35)
    at Zlib$1._error (index.js:5:35)
    at Zlib$1._write (index.js:5:35)
    at Zlib$1.writeSync (index.js:5:35)
    at Zlib._processChunk (index.js:5:35)
    at zlibBufferSync (index.js:5:35)
    at Object.inflateRawSync (index.js:5:35)
    at <anonymous>:1:6
jbghoul commented 1 year ago

I am currently working on a pull request