agentsqripts
Version:
Comprehensive static code analysis toolkit for identifying technical debt, security vulnerabilities, performance issues, and code quality problems
75 lines (67 loc) • 1.75 kB
JavaScript
/**
* @file Common process helpers with enhanced qerrors functionality
* @description Shared utilities for process handling with structured error management
*/
// Enhanced error handling using qerrors functionality
const {
handleAnalysisError,
createAnalysisError,
ErrorTypes,
ErrorSeverity,
sanitizeMessage,
simpleLog
} = require('../../cli/lib/errorHandler');
/**
* Exit process with code based on issues
* @param {boolean} hasIssues - Whether issues were found
*/
function exitWithCode(hasIssues) {
process.exit(hasIssues ? 1 : 0);
}
/**
* Exit process based on severity count
* @param {number} count - Count of severe issues
*/
function exitOnSeverity(count) {
process.exit(count > 0 ? 1 : 0);
}
/**
* Handle uncaught errors with enhanced qerrors functionality
* @param {Error} error - Error object
*/
async function handleUncaughtError(error) {
try {
// Create structured error with proper classification
const enhancedError = createAnalysisError(
`Uncaught error: ${error.message}`,
'system',
'CRITICAL'
);
// Log with critical severity
simpleLog.fatal(enhancedError.message, {
errorType: 'uncaught_error',
originalError: error.message,
stack: error.stack,
severity: 'CRITICAL'
});
// Still exit but with enhanced logging
process.exit(1);
} catch (loggingError) {
// Fallback to basic logging if qerrors fails
console.error('Uncaught error:', error);
process.exit(1);
}
}
/**
* Get process arguments
* @returns {Array} Command line arguments
*/
function getProcessArgs() {
return process.argv.slice(2);
}
module.exports = {
exitWithCode,
exitOnSeverity,
handleUncaughtError,
getProcessArgs
};