ursa-optional error handling not working #3

Slēgta
Ghost atvēra 2018-12-28 06:17:05 +00:00 · 2 komentāri

In 'generate-privkey.js', the following code has been written to provide a fallback if ursa fails to build:

 try {
    return require('./generate-privkey-node.js')(bitlen, exp);
  } catch(e) {
    if (!/generateKeyPairSync is not a function/.test(e.message)) {
      throw e;
    }
    try {
      return require('./generate-privkey-ursa.js')(bitlen, exp);
    } catch(e) {
      if (e.code !== 'MODULE_NOT_FOUND') {
        throw e;
      }
      if (!oldver) {
        oldver = true;
        console.warn("[WARN] rsa-compat: Your version of node does not have crypto.generateKeyPair()");
        console.warn("[WARN] rsa-compat: Please update to node >= v10.12 or 'npm install ursa'");
        console.warn("[WARN] rsa-compat: Using node-forge as a fallback, but it may be unacceptably slow.");

However, due to the check if (e.code !== 'MODULE_NOT_FOUND'), this code fails to fall back to forge in the event that the module "installs" but dosen't "build". I am not well versed enough in ursa to even know if that should be possible, but it has given me hell this evening, as the result is a cryptic error and a stalled server. Commenting out that check caused the module to fallback on forge and work as expected.

In 'generate-privkey.js', the following code has been written to provide a fallback if ursa fails to build: ``` try { return require('./generate-privkey-node.js')(bitlen, exp); } catch(e) { if (!/generateKeyPairSync is not a function/.test(e.message)) { throw e; } try { return require('./generate-privkey-ursa.js')(bitlen, exp); } catch(e) { if (e.code !== 'MODULE_NOT_FOUND') { throw e; } if (!oldver) { oldver = true; console.warn("[WARN] rsa-compat: Your version of node does not have crypto.generateKeyPair()"); console.warn("[WARN] rsa-compat: Please update to node >= v10.12 or 'npm install ursa'"); console.warn("[WARN] rsa-compat: Using node-forge as a fallback, but it may be unacceptably slow."); ``` However, due to the check `if (e.code !== 'MODULE_NOT_FOUND')`, this code fails to fall back to forge in the event that the module "installs" but dosen't "build". I am not well versed enough in ursa to even know if that should be possible, but it has given me hell this evening, as the result is a cryptic error and a stalled server. Commenting out that check caused the module to fallback on forge and work as expected.
Īpašnieks

Thanks for the report. That is a very strange condition.

Can you copy/paste the cryptic error message to me or give me a summary of what it said?

Thanks for the report. That is a very strange condition. Can you copy/paste the cryptic error message to me or give me a summary of what it said?
Īpašnieks

Closing due to inactivity.

Closing due to inactivity.
coolaj86 slēdza šo problēmu 2019-03-13 15:39:32 +00:00
Nepieciešams pieteikties, lai pievienotos šai sarunai.
Nav iezīmju
2 dalībnieki
Paziņojumi
Izpildes termiņš
Izpildes termiņš nav uzstādīts.
Atkarības

Nav atkarību.

Atsaucas uz: coolaj86/rsa-compat.js#3
Nav sniegts apraksts.