fix: use file.exists instead of try/catch to detect missing email logo (#14154)

The previous ENOENT check in getLogoSize never worked because image.size
passes the path directly to sharp, which throws a plain Error with message
"Input file is missing" rather than a Node.js ENOENT error. This caused
saving any admin settings to fail when brand:logo was set but the x50 file
was missing (e.g. after a fresh deployment).
This commit is contained in:
Dirk Plate
2026-04-07 15:11:54 +02:00
committed by GitHub
parent 62b65e69ab
commit 4366bdd0d8

View File

@@ -6,6 +6,7 @@ const path = require('path');
const winston = require('winston');
const db = require('../database');
const file = require('../file');
const pubsub = require('../pubsub');
const Meta = require('./index');
const translator = require('../translator');
@@ -212,20 +213,17 @@ async function getLogoSize(data) {
if (!data['brand:logo']) {
return;
}
const x50Path = path.join(nconf.get('upload_path'), 'system', 'site-logo-x50.png');
let size;
try {
size = await image.size(path.join(nconf.get('upload_path'), 'system', 'site-logo-x50.png'));
} catch (err) {
if (err.code === 'ENOENT') {
// For whatever reason the x50 logo wasn't generated, gracefully error out
winston.warn('[logo] The email-safe logo doesn\'t seem to have been created, please re-upload your site logo.');
size = {
height: 0,
width: 0,
};
} else {
throw err;
}
if (await file.exists(x50Path)) {
size = await image.size(x50Path);
} else {
// For whatever reason the x50 logo wasn't generated, gracefully error out
winston.warn('[logo] The email-safe logo doesn\'t seem to have been created, please re-upload your site logo.');
size = {
height: 0,
width: 0,
};
}
data['brand:emailLogo'] = nconf.get('url') + path.join(nconf.get('upload_url'), 'system', 'site-logo-x50.png');
data['brand:emailLogo:height'] = size.height;