fix: harden deploy error handling - guard against undefined errors, safeErrorMessage null check
- deploy.js: wrap logError/notification in try/catch so they never mask the original deploy error - deploy.js: use optional chaining for error.message access - logging.js: safeErrorMessage handles null/undefined error gracefully
This commit is contained in:
@@ -420,10 +420,11 @@ module.exports = function({ docker, caddy, credentialManager, servicesStateManag
|
||||
|
||||
res.json(response);
|
||||
} catch (error) {
|
||||
await logError('app-deploy', error, { appId, config });
|
||||
log.error('deploy', 'Deployment failed', { appId, error: error.message });
|
||||
try { await logError('app-deploy', error, { appId, config }); } catch (_) { /* logError failure should not mask original error */ }
|
||||
const msg = error?.message || String(error || 'Unknown error');
|
||||
log.error('deploy', 'Deployment failed', { appId, error: msg });
|
||||
const template = ctx.APP_TEMPLATES[appId];
|
||||
ctx.notification.send('deploymentFailed', 'Deployment Failed', `Failed to deploy **${template?.name || appId}**.\nError: ${error.message}`, 'error');
|
||||
try { ctx.notification.send('deploymentFailed', 'Deployment Failed', `Failed to deploy **${template?.name || appId}**.\nError: ${msg}`, 'error'); } catch (_) {}
|
||||
errorResponse(res, 500, ctx.safeErrorMessage(error));
|
||||
}
|
||||
}, 'apps-deploy'));
|
||||
|
||||
@@ -94,6 +94,7 @@ async function logError(ERROR_LOG_FILE, MAX_ERROR_LOG_SIZE, context, error, addi
|
||||
* Return a safe error message without leaking internals
|
||||
*/
|
||||
function safeErrorMessage(error) {
|
||||
if (!error) return 'An internal error occurred';
|
||||
const msg = error.message || String(error);
|
||||
|
||||
// Detect port conflict errors
|
||||
|
||||
Reference in New Issue
Block a user