@storm-software/config-tools
Version:
⚡The Storm-Ops monorepo contains utility applications, tools, and various libraries to create modern and scalable web applications.
50 lines (47 loc) • 1.59 kB
JavaScript
import {
writeError,
writeFatal,
writeSuccess,
writeTrace
} from "./chunk-XDS6C7HI.js";
import {
__name
} from "./chunk-SHUYVCID.js";
// src/utilities/process-handler.ts
var exitWithError = /* @__PURE__ */ __name((config) => {
writeFatal("Exiting script with an error status...", config);
process.exit(1);
}, "exitWithError");
var exitWithSuccess = /* @__PURE__ */ __name((config) => {
writeSuccess("Script completed successfully. Exiting...", config);
process.exit(0);
}, "exitWithSuccess");
var handleProcess = /* @__PURE__ */ __name((config) => {
writeTrace(`Using the following arguments to process the script: ${process.argv.join(", ")}`, config);
process.on("unhandledRejection", (error) => {
writeError(`An Unhandled Rejection occurred while running the program: ${error}`, config);
exitWithError(config);
});
process.on("uncaughtException", (error) => {
writeError(`An Uncaught Exception occurred while running the program: ${error.message}
Stacktrace: ${error.stack}`, config);
exitWithError(config);
});
process.on("SIGTERM", (signal) => {
writeError(`The program terminated with signal code: ${signal}`, config);
exitWithError(config);
});
process.on("SIGINT", (signal) => {
writeError(`The program terminated with signal code: ${signal}`, config);
exitWithError(config);
});
process.on("SIGHUP", (signal) => {
writeError(`The program terminated with signal code: ${signal}`, config);
exitWithError(config);
});
}, "handleProcess");
export {
exitWithError,
exitWithSuccess,
handleProcess
};