Error when apprise notifications are enabled but not emails + alerts are enabled
"Regression" (not really: the error is thrown only since this commit but the code should not be called) from 0bd57dde
When the notifications are enabled but only apprise is configured and there is no email configuration, we still call getEmailer.send()
(https://framagit.org/kresusapp/kresus/-/blob/master/server/lib/alert-manager.ts#L31), that will throw an error because I did not configure the emails.
Logs:
[2020-05-18T22:39:42.105] [INFO] apply-config - KRESUS_EMAIL_TRANSPORT = null
[2020-05-18T22:39:42.106] [INFO] apply-config - KRESUS_EMAIL_SENDMAIL_BIN = null
[2020-05-18T22:39:42.106] [INFO] apply-config - KRESUS_EMAIL_FROM = null
[2020-05-18T22:39:42.107] [INFO] apply-config - KRESUS_EMAIL_HOST = null
[2020-05-18T22:39:42.108] [INFO] apply-config - KRESUS_EMAIL_PORT = null
[2020-05-18T22:39:42.108] [INFO] apply-config - KRESUS_EMAIL_USER = null
[2020-05-18T22:39:42.109] [INFO] apply-config - KRESUS_EMAIL_PASSWORD = (hidden)
[2020-05-18T22:39:42.110] [INFO] apply-config - KRESUS_EMAIL_FORCE_TLS = false
[2020-05-18T22:39:42.110] [INFO] apply-config - KRESUS_EMAIL_REJECT_UNAUTHORIZED_TLS = true
[2020-05-18T22:39:42.111] [INFO] apply-config - KRESUS_APPRISE_API_BASE_URL = http://localhost:8000
...
[2020-05-18T22:40:53.002] [INFO] notifications - Notifier initialized for user 1
[2020-05-18T22:40:53.013] [INFO] notifications - Apprise url fetched for user 1
[2020-05-18T22:41:22.809] [WARN] emailer - One of emailFrom, smtpHost or smtpPort is missing: emails won't work.
[2020-05-18T22:41:22.811] [INFO] emailer - Reinitializing email recipient...
[2020-05-18T22:41:22.836] [INFO] emailer - Done!
[2020-05-18T22:41:22.837] [ERROR] helpers - Assertion error: fromEmail must have been initialized before sending emails
Error
at panic (/home/user/app/build/server/helpers.js:31:46)
at Object.assert (/home/user/app/build/server/helpers.js:38:9)
at Emailer.sendToUser (/home/user/app/build/server/lib/emailer.js:98:19)
at process._tickCallback (internal/process/next_tick.js:68:7)
[2020-05-18T22:41:22.838] [ERROR] alert-manager - Error when checking alerts for operations: Error: Assertion error: fromEmail must have been initialized before sending emails
Error
at panic (/home/user/app/build/server/helpers.js:31:46)
at Object.assert (/home/user/app/build/server/helpers.js:38:9)
at Emailer.sendToUser (/home/user/app/build/server/lib/emailer.js:98:19)
at process._tickCallback (internal/process/next_tick.js:68:7)
[2020-05-18T22:41:23.112] [INFO] accounts-manager - Post process: done.
Edited by Nicolas Frandeboeuf