@thexjs/core 1.8.0 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -795,15 +795,31 @@ declare function auditSessionRevoked(input: AuditEventInput & {
795
795
  *
796
796
  * These handlers report the crash through the configured error reporter so an
797
797
  * operator sees it, rather than dying silently (or staying up silently with no
798
- * trace of what happened). By default the process keeps serving; set
799
- * `exitOnCrash` to opt into crash-on-error semantics (e.g. when running under
800
- * a supervisor like systemd/K8s that restarts the box).
798
+ * trace of what happened).
799
+ *
800
+ * A throw that escapes to the event loop (module eval, background sweep,
801
+ * native callback, timer) leaves module-scope singletons in an undefined
802
+ * state, so the process must not keep serving corrupted traffic. By default
803
+ * an `uncaughtException` fails fast (`exitOnCrash` defaults `true`) so the
804
+ * orchestrator (systemd/K8s) restarts the box clean. Unhandled rejections are
805
+ * usually recoverable and stay survivable by default.
801
806
  */
802
807
  interface ProcessCrashHandlerOptions {
803
808
  /** Phase tag forwarded to the error reporter. Defaults to "api". */
804
809
  phase?: "ssr" | "action" | "api" | "loader";
805
- /** When true, `process.exit(1)` after reporting. Defaults to false. */
810
+ /**
811
+ * When true, `process.exit(1)` after an uncaught exception. Defaults to
812
+ * `true` — an uncaughtException can leave process singletons half-mutated,
813
+ * so it must fail fast for the orchestrator to restart clean. Set `false`
814
+ * to keep serving after reporting.
815
+ */
806
816
  exitOnCrash?: boolean;
817
+ /**
818
+ * When true, `process.exit(1)` after an unhandled rejection. Defaults to
819
+ * `false` — an unhandledRejection is usually a lone async failure the
820
+ * process can survive.
821
+ */
822
+ exitOnUnhandledRejection?: boolean;
807
823
  }
808
824
  /** Registers `uncaughtException`/`unhandledRejection` handlers; returns a disposer. */
809
825
  declare function installProcessCrashHandlers(options?: ProcessCrashHandlerOptions): () => void;
package/dist/index.js CHANGED
@@ -951,7 +951,9 @@ function buildServerEntry(opts, configImportPath, stylesheetHref) {
951
951
  "// a rejected promise from a background sweep) is reported through the",
952
952
  "// error reporter so the box reports instead of dying silently.",
953
953
  'const { installProcessCrashHandlers } = await import("@thexjs/core");',
954
- "installProcessCrashHandlers();"
954
+ // Fail fast on an uncaughtException: the singleton state may be corrupted,
955
+ // so drain and let the orchestrator restart clean (see crash-handlers).
956
+ "installProcessCrashHandlers({ exitOnCrash: true });"
955
957
  );
956
958
  return lines.join("\n");
957
959
  }
@@ -3024,16 +3026,17 @@ function auditSessionRevoked(input) {
3024
3026
  // src/observability/crash-handlers.ts
3025
3027
  function installProcessCrashHandlers(options = {}) {
3026
3028
  const phase = options.phase ?? "api";
3027
- const exitOnCrash = options.exitOnCrash ?? false;
3029
+ const exitOnUncaughtException = options.exitOnCrash ?? true;
3030
+ const exitOnUnhandledRejection = options.exitOnUnhandledRejection ?? false;
3028
3031
  const onUncaughtException = (error) => {
3029
3032
  console.error("[x] uncaught exception:", error);
3030
3033
  reportException(error, { phase });
3031
- if (exitOnCrash) process.exit(1);
3034
+ if (exitOnUncaughtException) process.exit(1);
3032
3035
  };
3033
3036
  const onUnhandledRejection = (reason) => {
3034
3037
  console.error("[x] unhandled rejection:", reason);
3035
3038
  reportException(reason, { phase });
3036
- if (exitOnCrash) process.exit(1);
3039
+ if (exitOnUnhandledRejection) process.exit(1);
3037
3040
  };
3038
3041
  process.on("uncaughtException", onUncaughtException);
3039
3042
  process.on("unhandledRejection", onUnhandledRejection);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thexjs/core",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
4
4
  "description": "Full-stack React framework core (router, SSR/SSG renderer, islands, server functions) for the x framework, built on Bun.",
5
5
  "keywords": [
6
6
  "react",