From 0d66480cd6890004b0645d23964c8fbe0356bbcf Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 2 Jun 2022 15:23:25 +0200 Subject: [PATCH] fix(crypto-nodejs): `OlmMachine.new` effectively raises an error. Returning an `napi::Error` doesn't raise it. We must return a `Result<_, napi::Error>` to ensure `napi` will raise the error as expected. --- crates/matrix-sdk-crypto-nodejs/src/machine.rs | 6 ++++-- crates/matrix-sdk-crypto-nodejs/tests/machine.test.js | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 crates/matrix-sdk-crypto-nodejs/tests/machine.test.js diff --git a/crates/matrix-sdk-crypto-nodejs/src/machine.rs b/crates/matrix-sdk-crypto-nodejs/src/machine.rs index 964b7cd1b..be6e7cd74 100644 --- a/crates/matrix-sdk-crypto-nodejs/src/machine.rs +++ b/crates/matrix-sdk-crypto-nodejs/src/machine.rs @@ -62,8 +62,10 @@ impl OlmMachine { /// asynchronous. Please use the `finalize` method. #[napi(constructor)] #[allow(clippy::new_ret_no_self)] - pub fn new() -> napi::Error { - napi::Error::from_reason("To build an `OldMachine`, please use the `initialize` method") + pub fn new() -> Result<(), napi::Error> { + Err(napi::Error::from_reason( + "To build an `OldMachine`, please use the `initialize` method", + )) } /// The unique user ID that owns this `OlmMachine` instance. diff --git a/crates/matrix-sdk-crypto-nodejs/tests/machine.test.js b/crates/matrix-sdk-crypto-nodejs/tests/machine.test.js new file mode 100644 index 000000000..b996f2b6e --- /dev/null +++ b/crates/matrix-sdk-crypto-nodejs/tests/machine.test.js @@ -0,0 +1,7 @@ +const { OlmMachine } = require('../'); + +describe(OlmMachine.name, () => { + test('cannot be instantiated', () => { + expect(() => { new OlmMachine() }).toThrow(); + }); +});