const { logError } = require('./LogContext');

const safeExecute = async (handler, context = {}, fallback = null) => {
  try {
    return await handler();
  } catch (error) {
    logError('Module execution failed', {
      ...context,
      error: error.message || String(error)
    });
    return fallback;
  }
};

module.exports = { safeExecute };
