import {
  writeError,
  writeFatal,
  writeSuccess,
  writeTrace
} from "./chunk-4RQGNE37.js";
import {
  __name,
  init_esm_shims
} from "./chunk-BFNZYC5O.js";

// src/utilities/process-handler.ts
init_esm_shims();
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
};
