Skip to content

Commit 99a2c16

Browse files
panvadanielleadams
authored andcommitted
crypto: add causes to applicable webcrypto's OperationError
PR-URL: #44890 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 803fbfb commit 99a2c16

File tree

6 files changed

+6
-12
lines changed

6 files changed

+6
-12
lines changed

lib/internal/crypto/aes.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,10 @@ async function aesGenerateKey(algorithm, extractable, keyUsages) {
241241
}
242242

243243
const key = await generateKey('aes', { length }).catch((err) => {
244-
// TODO(@panva): add err as cause to DOMException
245244
throw lazyDOMException(
246245
'The operation failed for an operation-specific reason' +
247246
`[${err.message}]`,
248-
'OperationError');
247+
{ name: 'OperationError', cause: err });
249248
});
250249

251250
return new InternalCryptoKey(

lib/internal/crypto/cfrg.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,9 @@ async function cfrgGenerateKey(algorithm, extractable, keyUsages) {
150150
}
151151

152152
const keyPair = await generateKeyPair(genKeyType).catch((err) => {
153-
// TODO(@panva): add err as cause to DOMException
154153
throw lazyDOMException(
155154
'The operation failed for an operation-specific reason',
156-
'OperationError');
155+
{ name: 'OperationError', cause: err });
157156
});
158157

159158
let publicUsages;

lib/internal/crypto/ec.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,9 @@ async function ecGenerateKey(algorithm, extractable, keyUsages) {
112112
}
113113

114114
const keypair = await generateKeyPair('ec', { namedCurve }).catch((err) => {
115-
// TODO(@panva): add err as cause to DOMException
116115
throw lazyDOMException(
117116
'The operation failed for an operation-specific reason',
118-
'OperationError');
117+
{ name: 'OperationError', cause: err });
119118
});
120119

121120
let publicUsages;

lib/internal/crypto/mac.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,9 @@ async function hmacGenerateKey(algorithm, extractable, keyUsages) {
6666
}
6767

6868
const key = await generateKey('hmac', { length }).catch((err) => {
69-
// TODO(@panva): add err as cause to DOMException
7069
throw lazyDOMException(
7170
'The operation failed for an operation-specific reason',
72-
'OperationError');
71+
{ name: 'OperationError', cause: err });
7372
});
7473

7574
return new InternalCryptoKey(

lib/internal/crypto/rsa.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,9 @@ async function rsaKeyGenerate(
178178
modulusLength,
179179
publicExponent: publicExponentConverted,
180180
}).catch((err) => {
181-
// TODO(@panva): add err as cause to DOMException
182181
throw lazyDOMException(
183182
'The operation failed for an operation-specific reason',
184-
'OperationError');
183+
{ name: 'OperationError', cause: err });
185184
});
186185

187186
const keyAlgorithm = {

lib/internal/crypto/util.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,9 @@ const validateByteSource = hideStackFrames((val, name) => {
279279

280280
function onDone(resolve, reject, err, result) {
281281
if (err) {
282-
// TODO(@panva): add err as cause to DOMException
283282
return reject(lazyDOMException(
284283
'The operation failed for an operation-specific reason',
285-
'OperationError'));
284+
{ name: 'OperationError', cause: err }));
286285
}
287286
resolve(result);
288287
}

0 commit comments

Comments
 (0)