Skip to content

Commit 899e914

Browse files
committed
zlib: throw brotli initialization error from c++
1 parent 2f0b371 commit 899e914

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

lib/internal/errors.js

-1
Original file line numberDiff line numberDiff line change
@@ -1886,4 +1886,3 @@ E('ERR_WORKER_UNSERIALIZABLE_ERROR',
18861886
'Serializing an uncaught exception failed', Error);
18871887
E('ERR_WORKER_UNSUPPORTED_OPERATION',
18881888
'%s is not supported in workers', TypeError);
1889-
E('ERR_ZLIB_INITIALIZATION_FAILED', 'Initialization failed', Error);

lib/zlib.js

+2-9
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ const {
4747
ERR_BUFFER_TOO_LARGE,
4848
ERR_INVALID_ARG_TYPE,
4949
ERR_OUT_OF_RANGE,
50-
ERR_ZLIB_INITIALIZATION_FAILED,
5150
},
5251
genericNodeError,
5352
} = require('internal/errors');
@@ -816,14 +815,8 @@ function Brotli(opts, mode) {
816815
new binding.BrotliDecoder(mode) : new binding.BrotliEncoder(mode);
817816

818817
this._writeState = new Uint32Array(2);
819-
// TODO(addaleax): Sometimes we generate better error codes in C++ land,
820-
// e.g. ERR_BROTLI_PARAM_SET_FAILED -- it's hard to access them with
821-
// the current bindings setup, though.
822-
if (!handle.init(brotliInitParamsArray,
823-
this._writeState,
824-
processCallback)) {
825-
throw new ERR_ZLIB_INITIALIZATION_FAILED();
826-
}
818+
819+
handle.init(brotliInitParamsArray, this._writeState, processCallback);
827820

828821
ReflectApply(ZlibBase, this, [opts, mode, handle, brotliDefaultOpts]);
829822
}

src/node_errors.h

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ void OOMErrorHandler(const char* location, const v8::OOMDetails& details);
108108
V(ERR_VM_MODULE_CACHED_DATA_REJECTED, Error) \
109109
V(ERR_VM_MODULE_LINK_FAILURE, Error) \
110110
V(ERR_WASI_NOT_STARTED, Error) \
111+
V(ERR_ZLIB_INITIALIZATION_FAILED, Error) \
111112
V(ERR_WORKER_INIT_FAILED, Error) \
112113
V(ERR_PROTO_ACCESS, Error)
113114

src/node_zlib.cc

+11-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "async_wrap-inl.h"
2727
#include "env-inl.h"
28+
#include "node_errors.h"
2829
#include "node_external_reference.h"
2930
#include "threadpoolwork-inl.h"
3031
#include "util-inl.h"
@@ -271,6 +272,8 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork {
271272
CHECK_EQ(unreported_allocations_, 0);
272273
}
273274

275+
Environment* env() const { return this->ThreadPoolWork::env(); }
276+
274277
void Close() {
275278
if (write_in_progress_) {
276279
pending_close_ = true;
@@ -661,6 +664,10 @@ class BrotliCompressionStream final :
661664
context()->SetMode(mode);
662665
}
663666

667+
Environment* env() {
668+
return this->CompressionStream<CompressionContext>::env();
669+
}
670+
664671
inline CompressionContext* context() {
665672
return this->CompressionStream<CompressionContext>::context();
666673
}
@@ -694,7 +701,8 @@ class BrotliCompressionStream final :
694701
static_cast<CompressionStream<CompressionContext>*>(wrap));
695702
if (err.IsError()) {
696703
wrap->EmitError(err);
697-
args.GetReturnValue().Set(false);
704+
THROW_ERR_ZLIB_INITIALIZATION_FAILED(wrap->env(),
705+
"Initialization failed");
698706
return;
699707
}
700708

@@ -708,12 +716,11 @@ class BrotliCompressionStream final :
708716
err = wrap->context()->SetParams(i, data[i]);
709717
if (err.IsError()) {
710718
wrap->EmitError(err);
711-
args.GetReturnValue().Set(false);
719+
THROW_ERR_ZLIB_INITIALIZATION_FAILED(wrap->env(),
720+
"Initialization failed");
712721
return;
713722
}
714723
}
715-
716-
args.GetReturnValue().Set(true);
717724
}
718725

719726
static void Params(const FunctionCallbackInfo<Value>& args) {

0 commit comments

Comments
 (0)