Files
wekan/server/lib/notificationFailureReason.js
T
Lauri Ojansivu bf7520f972 Activity notification failures say which check failed.
"Activity notification delivery incomplete; pending intent retained" was
logged for nearly every activity - 1,080 times in one test-server run,
and on a production server one line after another - and never said why:
the .catch() dropped the error. It and the recovery and both cleanup
lines now carry the failure's code (activity-notification-intent-invalid,
sync-busy, ...). Only a code is logged as it is; any other error gives its
name and numeric or short code, never its message, which may carry an
address or a card title. tests/notificationFailureReason.test.cjs pins
that, and fails when a notification failure line in server/ drops its
reason again.

Thanks to xet7 !
2026-10-25 03:18:15 +03:00

27 lines
1.3 KiB
JavaScript

'use strict';
// What a notification log line may say about why it failed.
//
// The activity notification pipeline throws plain codes - "activity-
// notification-intent-invalid", "sync-busy" - and its log lines dropped them:
// "Activity notification delivery incomplete; pending intent retained", a
// thousand times in one test run, said that something failed and never which
// check. A code is safe to log, it is how the failure is found, and it is what
// this returns. Anything else - a database error, a TypeError - may carry
// document content or an address in its message, so only its name and code are
// given, never the message.
const CODE = /^[a-z0-9]+(?:-[a-z0-9]+)+$/; // at least one hyphen: a code, not a word
function notificationFailureReason(error) {
if (!error) return 'unknown';
const message = typeof error.message === 'string' ? error.message : '';
if (message.length <= 100 && CODE.test(message)) return message;
const name = typeof error.name === 'string' && /^[A-Za-z]{1,60}$/.test(error.name) ? error.name : 'Error';
const code = error.code;
if (typeof code === 'number' && Number.isFinite(code)) return `${name} ${code}`;
if (typeof code === 'string' && code.length <= 60 && /^[A-Za-z0-9_.-]+$/.test(code)) return `${name} ${code}`;
return name;
}
module.exports = { notificationFailureReason };