Repository navigation
Add Node's error codes to the one-shot node:zlib APIs - #8610
Conversation
The one-shot node:zlib functions (deflateSync, gunzip(cb), brotliCompressSync, zstdDecompress(cb) and the rest) go straight into C++. Their errors have the same types as Node's, but they don't carry Node's `code`. A non-buffer input threw a JSG TypeError, a corrupt stream threw a plain Error without `code` or `errno`, and an out-of-range option or an oversized output threw a bare RangeError. The streaming classes already set these, so the same failure looked different depending on which API you used. In this patch: - the one-shot functions check their input in TypeScript and throw `ERR_INVALID_ARG_TYPE` with Node's message. Strings, ArrayBufferViews and ArrayBuffers are accepted as before. - a zlib, brotli or zstd error from a one-shot call carries the engine's `code` (e.g. `Z_DATA_ERROR`) and `errno`, as the stream path does. - the `chunkSize`, `maxOutputLength`, `flush` and `finishFlush` range checks throw with `code: 'ERR_OUT_OF_RANGE'`, and the zlib `finishFlush` message now reports the `finishFlush` value instead of `flush`. - exceeding `maxOutputLength` sets `code: 'ERR_BUFFER_TOO_LARGE'`. The message stays "Memory limit exceeded". No thrown type changes, and apart from the `finishFlush` value no message changes. Errors only gain properties, so this ships without a compatibility flag. The TODOs in zlib-nodejs-test now assert the codes, and a new `oneShotErrorCodes` case covers the accepted inputs and the range checks.
There was a problem hiding this comment.
✅ Approved — No problems found. The error codes, errno and the finishFlush message fix are applied the same way across the zlib, brotli and zstd one-shot paths, and the tests cover them.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No security concerns.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md concerns.
📋 Code Quality: ✅ LGTM
The changes are applied the same way across all one-shot entry points. Errors raised inside the callback variants reach the callback with code and errno set. The finishFlush message now reports the right value.
⚡ Performance: ✅ LGTM
The new code runs only on error paths, plus one constant-time type check per call. Buffer handling is unchanged.
📝 Documentation: ✅ LGTM
No documentation concerns.
Reviewed commit: 40c7777a
The one-shot node:zlib functions (deflateSync, gunzip(cb), brotliCompressSync, zstdDecompress(cb) and the rest) go straight into C++. Their errors have the same types as Node's, but they don't carry Node's
code. A non-buffer input threw a JSG TypeError, a corrupt stream threw a plain Error withoutcodeorerrno, and an out-of-range option or an oversized output threw a bare RangeError. The streaming classes already set these, so the same failure looked different depending on which API you used.In this patch:
ERR_INVALID_ARG_TYPEwith Node's message. Strings, ArrayBufferViews and ArrayBuffers are accepted as before.code(e.g.Z_DATA_ERROR) anderrno, as the stream path does.chunkSize,maxOutputLength,flushandfinishFlushrange checks throw withcode: 'ERR_OUT_OF_RANGE', and the zlibfinishFlushmessage now reports thefinishFlushvalue instead offlush.maxOutputLengthsetscode: 'ERR_BUFFER_TOO_LARGE'. The message stays "Memory limit exceeded".No thrown type changes, and apart from the
finishFlushvalue no message changes. Errors only gain properties, so this ships without a compatibility flag. The TODOs in zlib-nodejs-test now assert the codes, and a newoneShotErrorCodescase covers the accepted inputs and the range checks.