You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-26 17:03:12 +03:00
Fix logging of DecryptionErrors to be more useful
We were relying on being able to override toString in DecryptionError, which (a) doesn't work thanks to https://github.com/babel/babel/issues/3083, and (b) was a bit naughty anyway. Instead, just add a detailedString property and use that.
This commit is contained in:
@@ -179,30 +179,25 @@ class DecryptionError extends Error {
|
|||||||
constructor(msg, details) {
|
constructor(msg, details) {
|
||||||
super(msg);
|
super(msg);
|
||||||
this.name = 'DecryptionError';
|
this.name = 'DecryptionError';
|
||||||
this.details = details;
|
this.detailedString = _detailedStringForDecryptionError(this, details);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
export {DecryptionError}; // https://github.com/jsdoc3/jsdoc/issues/1272
|
||||||
|
|
||||||
/**
|
function _detailedStringForDecryptionError(err, details) {
|
||||||
* override the string used when logging
|
let result = err.name + '[msg: ' + err.message;
|
||||||
*
|
|
||||||
* @returns {String}
|
|
||||||
*/
|
|
||||||
toString() {
|
|
||||||
let result = this.name + '[msg: ' + this.message;
|
|
||||||
|
|
||||||
if (this.details) {
|
if (details) {
|
||||||
result += ', ' +
|
result += ', ' +
|
||||||
Object.keys(this.details).map(
|
Object.keys(details).map(
|
||||||
(k) => k + ': ' + this.details[k],
|
(k) => k + ': ' + details[k],
|
||||||
).join(', ');
|
).join(', ');
|
||||||
}
|
}
|
||||||
|
|
||||||
result += ']';
|
result += ']';
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
export {DecryptionError}; // https://github.com/jsdoc3/jsdoc/issues/1272
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exception thrown specifically when we want to warn the user to consider
|
* Exception thrown specifically when we want to warn the user to consider
|
||||||
|
|||||||
@@ -424,7 +424,7 @@ utils.extend(module.exports.MatrixEvent.prototype, {
|
|||||||
// decryption error, but we have a retry queued.
|
// decryption error, but we have a retry queued.
|
||||||
console.log(
|
console.log(
|
||||||
`Got error decrypting event (id=${this.getId()}: ` +
|
`Got error decrypting event (id=${this.getId()}: ` +
|
||||||
`${e.message}), but retrying`,
|
`${e}), but retrying`,
|
||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -432,7 +432,7 @@ utils.extend(module.exports.MatrixEvent.prototype, {
|
|||||||
// decryption error, no retries queued. Warn about the error and
|
// decryption error, no retries queued. Warn about the error and
|
||||||
// set it to m.bad.encrypted.
|
// set it to m.bad.encrypted.
|
||||||
console.warn(
|
console.warn(
|
||||||
`Error decrypting event (id=${this.getId()}): ${e}`,
|
`Error decrypting event (id=${this.getId()}): ${e.detailedString}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
res = this._badEncryptedMessage(e.message);
|
res = this._badEncryptedMessage(e.message);
|
||||||
|
|||||||
Reference in New Issue
Block a user