bktide
Version:
Command-line interface for Buildkite CI/CD workflows with rich shell completions (Fish, Bash, Zsh) and Alfred workflow integration for macOS power users
59 lines • 1.66 kB
JavaScript
/**
* Error handling utilities
*/
import * as sourceMap from 'source-map-support';
import { logger } from '../services/logger.js';
import { displayCLIError } from './cli-error-handler.js';
/**
* Initialize error handling for the application
*/
export function initializeErrorHandling() {
// Install source map support for better stack traces
sourceMap.install({
handleUncaughtExceptions: false,
hookRequire: true
});
// Set up handlers for uncaught exceptions and unhandled rejections
process.on('uncaughtException', (err) => {
displayCLIError(err, false);
});
process.on('unhandledRejection', (reason) => {
displayCLIError(reason, false);
});
logger.debug('Error handling system initialized');
}
/**
* Log an error with proper formatting
* @param error The error to log
*/
export function logError(error) {
if (error instanceof Error) {
logger.error(error, 'Error occurred');
}
else {
logger.error({ error }, 'Unknown error occurred');
}
}
/**
* Wrap an async function with better error handling
*
* @param fn Function to wrap
* @returns Wrapped function with better error handling
*/
export function withErrorHandling(fn) {
return async function (...args) {
try {
return await fn(...args);
}
catch (error) {
if (error instanceof Error) {
logger.error(error, 'Error occurred');
}
else {
logger.error({ error }, 'Unknown error occurred');
}
throw error;
}
};
}
//# sourceMappingURL=errorUtils.js.map