From afbb3f406e4da67c16d22ba50f726f02ed5e3009 Mon Sep 17 00:00:00 2001
From: Pedro Castro <aspeddro@gmail.com>
Date: Sat, 3 Aug 2024 21:02:07 -0300
Subject: [PATCH 1/6] Cleanup Js.Exn functions

---
 jscomp/others/js_exn.res                | 68 ++++++++++++-------------
 jscomp/others/js_exn.resi               | 12 ++---
 jscomp/runtime/release.ninja            |  6 +--
 jscomp/test/js_exception_catch_test.js  | 15 +++---
 jscomp/test/js_exception_catch_test.res |  6 +--
 lib/es6/js_exn.js                       | 53 +++----------------
 lib/es6/js_null.js                      |  7 ++-
 lib/es6/js_option.js                    |  7 ++-
 lib/es6/js_undefined.js                 |  7 ++-
 lib/js/js_exn.js                        | 53 +++----------------
 lib/js/js_null.js                       |  7 ++-
 lib/js/js_option.js                     |  7 ++-
 lib/js/js_undefined.js                  |  7 ++-
 13 files changed, 99 insertions(+), 156 deletions(-)

diff --git a/jscomp/others/js_exn.res b/jscomp/others/js_exn.res
index 9cd37bc19b..fa33fac537 100644
--- a/jscomp/others/js_exn.res
+++ b/jscomp/others/js_exn.res
@@ -34,44 +34,44 @@ external asJsExn: exn => option<t> = "?as_js_exn"
 @get external name: t => option<string> = "name"
 @get external fileName: t => option<string> = "fileName"
 
-type error
-@new external makeError: string => error = "Error"
+// type error
+// @new external makeError: string => error = "Error"
 external isCamlExceptionOrOpenVariant: 'a => bool = "?is_extension"
 
 external anyToExnInternal: 'a => exn = "#wrap_exn"
 
-let raiseError = str => raise((Obj.magic((makeError(str): error)): exn))
-
-type eval_error
-@new external makeEvalError: string => eval_error = "EvalError"
-
-let raiseEvalError = str => raise((Obj.magic((makeEvalError(str): eval_error)): exn))
-
-type range_error
-@new external makeRangeError: string => range_error = "RangeError"
-
-let raiseRangeError = str => raise((Obj.magic((makeRangeError(str): range_error)): exn))
-
-type reference_error
-
-@new external makeReferenceError: string => reference_error = "ReferenceError"
-
-let raiseReferenceError = str => raise(Obj.magic(makeReferenceError(str)))
-
-type syntax_error
-@new external makeSyntaxError: string => syntax_error = "SyntaxError"
-
-let raiseSyntaxError = str => raise(Obj.magic(makeSyntaxError(str)))
-
-type type_error
-@new external makeTypeError: string => type_error = "TypeError"
-
-let raiseTypeError = str => raise(Obj.magic(makeTypeError(str)))
-
-type uri_error
-@new external makeURIError: string => uri_error = "URIError"
-
-let raiseUriError = str => raise(Obj.magic(makeURIError(str)))
+let raiseError = str => raise(Failure(str))
+
+// type eval_error
+// @new external makeEvalError: string => eval_error = "EvalError"
+//
+// let raiseEvalError = str => raise((Obj.magic((makeEvalError(str): eval_error)): exn))
+//
+// type range_error
+// @new external makeRangeError: string => range_error = "RangeError"
+//
+// let raiseRangeError = str => raise((Obj.magic((makeRangeError(str): range_error)): exn))
+//
+// type reference_error
+//
+// @new external makeReferenceError: string => reference_error = "ReferenceError"
+//
+// let raiseReferenceError = str => raise(Obj.magic(makeReferenceError(str)))
+//
+// type syntax_error
+// @new external makeSyntaxError: string => syntax_error = "SyntaxError"
+//
+// let raiseSyntaxError = str => raise(Obj.magic(makeSyntaxError(str)))
+//
+// type type_error
+// @new external makeTypeError: string => type_error = "TypeError"
+//
+// let raiseTypeError = str => raise(Obj.magic(makeTypeError(str)))
+//
+// type uri_error
+// @new external makeURIError: string => uri_error = "URIError"
+//
+// let raiseUriError = str => raise(Obj.magic(makeURIError(str)))
 
 /* TODO add predicate to tell which error is which " */
 
diff --git a/jscomp/others/js_exn.resi b/jscomp/others/js_exn.resi
index 87ce8ca887..e4faaa6be4 100644
--- a/jscomp/others/js_exn.resi
+++ b/jscomp/others/js_exn.resi
@@ -68,9 +68,9 @@ external anyToExnInternal: 'a => exn = "#wrap_exn"
 
 /** Raise Js exception Error object with stacktrace */
 let raiseError: string => 'a
-let raiseEvalError: string => 'a
-let raiseRangeError: string => 'a
-let raiseReferenceError: string => 'a
-let raiseSyntaxError: string => 'a
-let raiseTypeError: string => 'a
-let raiseUriError: string => 'a
+// let raiseEvalError: string => 'a
+// let raiseRangeError: string => 'a
+// let raiseReferenceError: string => 'a
+// let raiseSyntaxError: string => 'a
+// let raiseTypeError: string => 'a
+// let raiseUriError: string => 'a
diff --git a/jscomp/runtime/release.ninja b/jscomp/runtime/release.ninja
index 9b7f58df4c..b848fd71bc 100644
--- a/jscomp/runtime/release.ninja
+++ b/jscomp/runtime/release.ninja
@@ -25,7 +25,7 @@ o runtime/caml_exceptions.cmj : cc_cmi runtime/caml_exceptions.res | runtime/cam
 o runtime/caml_exceptions.cmi : cc runtime/caml_exceptions.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
 o runtime/caml_float.cmj : cc_cmi runtime/caml_float.res | runtime/caml_float.cmi runtime/caml_float_extern.cmj
 o runtime/caml_float.cmi : cc runtime/caml_float.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
-o runtime/caml_format.cmj : cc_cmi runtime/caml_format.res | runtime/caml_float.cmj runtime/caml_float_extern.cmj runtime/caml_format.cmi runtime/caml_int64.cmj runtime/caml_int64_extern.cmj runtime/caml_nativeint_extern.cmj runtime/caml_string_extern.cmj
+o runtime/caml_format.cmj : cc_cmi runtime/caml_format.res | runtime/caml.cmj runtime/caml_float.cmj runtime/caml_float_extern.cmj runtime/caml_format.cmi runtime/caml_int64.cmj runtime/caml_int64_extern.cmj runtime/caml_nativeint_extern.cmj runtime/caml_string_extern.cmj
 o runtime/caml_format.cmi : cc runtime/caml_format.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
 o runtime/caml_hash.cmj : cc_cmi runtime/caml_hash.res | runtime/caml_hash.cmi runtime/caml_hash_primitive.cmj runtime/caml_nativeint_extern.cmj
 o runtime/caml_hash.cmi : cc runtime/caml_hash.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
@@ -41,7 +41,7 @@ o runtime/caml_md5.cmj : cc_cmi runtime/caml_md5.res | runtime/caml_array_extern
 o runtime/caml_md5.cmi : cc runtime/caml_md5.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
 o runtime/caml_module.cmj : cc_cmi runtime/caml_module.res | runtime/caml_array_extern.cmj runtime/caml_module.cmi runtime/caml_obj.cmj
 o runtime/caml_module.cmi : cc runtime/caml_module.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
-o runtime/caml_obj.cmj : cc_cmi runtime/caml_obj.res | runtime/caml_array_extern.cmj runtime/caml_obj.cmi runtime/caml_option.cmj
+o runtime/caml_obj.cmj : cc_cmi runtime/caml_obj.res | runtime/caml.cmj runtime/caml_array_extern.cmj runtime/caml_obj.cmi runtime/caml_option.cmj
 o runtime/caml_obj.cmi : cc runtime/caml_obj.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
 o runtime/caml_option.cmj : cc_cmi runtime/caml_option.res | runtime/caml_option.cmi runtime/caml_undefined_extern.cmj
 o runtime/caml_option.cmi : cc runtime/caml_option.resi | runtime/bs_stdlib_mini.cmi runtime/caml_undefined_extern.cmj runtime/js.cmi runtime/js.cmj
@@ -57,7 +57,7 @@ o runtime/caml_array_extern.cmi runtime/caml_array_extern.cmj : cc runtime/caml_
 o runtime/caml_bigint_extern.cmi runtime/caml_bigint_extern.cmj : cc runtime/caml_bigint_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
 o runtime/caml_float_extern.cmi runtime/caml_float_extern.cmj : cc runtime/caml_float_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
 o runtime/caml_int64_extern.cmi runtime/caml_int64_extern.cmj : cc runtime/caml_int64_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
-o runtime/caml_js_exceptions.cmi runtime/caml_js_exceptions.cmj : cc runtime/caml_js_exceptions.res | runtime/bs_stdlib_mini.cmi runtime/caml_exceptions.cmj runtime/js.cmi runtime/js.cmj
+o runtime/caml_js_exceptions.cmi runtime/caml_js_exceptions.cmj : cc runtime/caml_js_exceptions.res | runtime/bs_stdlib_mini.cmi runtime/caml_exceptions.cmj runtime/caml_option.cmj runtime/js.cmi runtime/js.cmj
 o runtime/caml_nativeint_extern.cmi runtime/caml_nativeint_extern.cmj : cc runtime/caml_nativeint_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
 o runtime/caml_string_extern.cmi runtime/caml_string_extern.cmj : cc runtime/caml_string_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
 o runtime/caml_undefined_extern.cmi runtime/caml_undefined_extern.cmj : cc runtime/caml_undefined_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
diff --git a/jscomp/test/js_exception_catch_test.js b/jscomp/test/js_exception_catch_test.js
index 0d08a67689..7bdc8c0577 100644
--- a/jscomp/test/js_exception_catch_test.js
+++ b/jscomp/test/js_exception_catch_test.js
@@ -122,8 +122,8 @@ function test(f) {
       } else {
         return "C";
       }
-    } else if (e.RE_EXN_ID === Js_exn.$$Error) {
-      return "Js_error";
+    } else if (e.RE_EXN_ID === "Failure") {
+      return "Failure";
     } else {
       return "Any";
     }
@@ -207,10 +207,13 @@ eq("File \"js_exception_catch_test.res\", line 52, characters 5-12", test(functi
 }), "C_any");
 
 eq("File \"js_exception_catch_test.res\", line 53, characters 5-12", test(function () {
-  throw new Error(new Error("x").RE_EXN_ID, {
-        cause: new Error("x")
+  throw new Error("Failure", {
+        cause: {
+          RE_EXN_ID: "Failure",
+          _1: "x"
+        }
       });
-}), "Js_error");
+}), "Failure");
 
 eq("File \"js_exception_catch_test.res\", line 54, characters 5-12", test(function () {
   throw new Error("Failure", {
@@ -219,7 +222,7 @@ eq("File \"js_exception_catch_test.res\", line 54, characters 5-12", test(functi
           _1: "x"
         }
       });
-}), "Any");
+}), "Failure");
 
 Mt.from_pair_suites("Js_exception_catch_test", suites.contents);
 
diff --git a/jscomp/test/js_exception_catch_test.res b/jscomp/test/js_exception_catch_test.res
index 899a4f84f2..81d0a96c34 100644
--- a/jscomp/test/js_exception_catch_test.res
+++ b/jscomp/test/js_exception_catch_test.res
@@ -36,7 +36,7 @@ let test = f =>
   | B => #B
   | C(1, 2) => #C
   | C(_) => #C_any
-  | Js.Exn.Error(_) => #Js_error
+  | Failure(_) => #Failure
   | e => #Any
   }
 
@@ -50,8 +50,8 @@ let () = {
   eq(__LOC__, test(_ => raise(B)), #B)
   eq(__LOC__, test(_ => raise(C(1, 2))), #C)
   eq(__LOC__, test(_ => raise(C(0, 2))), #C_any)
-  eq(__LOC__, test(_ => Js.Exn.raiseError("x")), #Js_error)
-  eq(__LOC__, test(_ => failwith("x")), #Any)
+  eq(__LOC__, test(_ => Js.Exn.raiseError("x")), #Failure)
+  eq(__LOC__, test(_ => failwith("x")), #Failure)
 }
 
 let () = Mt.from_pair_suites(__MODULE__, suites.contents)
diff --git a/lib/es6/js_exn.js b/lib/es6/js_exn.js
index 6df4f31f32..175a30d196 100644
--- a/lib/es6/js_exn.js
+++ b/lib/es6/js_exn.js
@@ -2,57 +2,18 @@
 
 
 function raiseError(str) {
-  throw new Error(new Error(str).RE_EXN_ID, {
-        cause: new Error(str)
+  throw new Error("Failure", {
+        cause: {
+          RE_EXN_ID: "Failure",
+          _1: str
+        }
       });
 }
 
-function raiseEvalError(str) {
-  throw new Error(new EvalError(str).RE_EXN_ID, {
-        cause: new EvalError(str)
-      });
-}
-
-function raiseRangeError(str) {
-  throw new Error(new RangeError(str).RE_EXN_ID, {
-        cause: new RangeError(str)
-      });
-}
-
-function raiseReferenceError(str) {
-  throw new Error(new ReferenceError(str).RE_EXN_ID, {
-        cause: new ReferenceError(str)
-      });
-}
-
-function raiseSyntaxError(str) {
-  throw new Error(new SyntaxError(str).RE_EXN_ID, {
-        cause: new SyntaxError(str)
-      });
-}
-
-function raiseTypeError(str) {
-  throw new Error(new TypeError(str).RE_EXN_ID, {
-        cause: new TypeError(str)
-      });
-}
-
-function raiseUriError(str) {
-  throw new Error(new URIError(str).RE_EXN_ID, {
-        cause: new URIError(str)
-      });
-}
-
-let $$Error$1 = "JsError";
+let $$Error = "JsError";
 
 export {
-  $$Error$1 as $$Error,
+  $$Error,
   raiseError,
-  raiseEvalError,
-  raiseRangeError,
-  raiseReferenceError,
-  raiseSyntaxError,
-  raiseTypeError,
-  raiseUriError,
 }
 /* No side effect */
diff --git a/lib/es6/js_null.js b/lib/es6/js_null.js
index c6706e56a8..72a8bdcbc6 100644
--- a/lib/es6/js_null.js
+++ b/lib/es6/js_null.js
@@ -10,8 +10,11 @@ function getExn(f) {
   if (f !== null) {
     return f;
   }
-  throw new Error(new Error("Js.Null.getExn").RE_EXN_ID, {
-        cause: new Error("Js.Null.getExn")
+  throw new Error("Failure", {
+        cause: {
+          RE_EXN_ID: "Failure",
+          _1: "Js.Null.getExn"
+        }
       });
 }
 
diff --git a/lib/es6/js_option.js b/lib/es6/js_option.js
index 73e0a2f8ad..be8043e118 100644
--- a/lib/es6/js_option.js
+++ b/lib/es6/js_option.js
@@ -26,8 +26,11 @@ function getExn(x) {
   if (x !== undefined) {
     return Caml_option.valFromOption(x);
   }
-  throw new Error(new Error("getExn").RE_EXN_ID, {
-        cause: new Error("getExn")
+  throw new Error("Failure", {
+        cause: {
+          RE_EXN_ID: "Failure",
+          _1: "getExn"
+        }
       });
 }
 
diff --git a/lib/es6/js_undefined.js b/lib/es6/js_undefined.js
index 68411f013f..4f20b8854a 100644
--- a/lib/es6/js_undefined.js
+++ b/lib/es6/js_undefined.js
@@ -14,8 +14,11 @@ function getExn(f) {
   if (f !== undefined) {
     return f;
   }
-  throw new Error(new Error("Js.Undefined.getExn").RE_EXN_ID, {
-        cause: new Error("Js.Undefined.getExn")
+  throw new Error("Failure", {
+        cause: {
+          RE_EXN_ID: "Failure",
+          _1: "Js.Undefined.getExn"
+        }
       });
 }
 
diff --git a/lib/js/js_exn.js b/lib/js/js_exn.js
index 5229577c1f..5a44ef3060 100644
--- a/lib/js/js_exn.js
+++ b/lib/js/js_exn.js
@@ -2,55 +2,16 @@
 
 
 function raiseError(str) {
-  throw new Error(new Error(str).RE_EXN_ID, {
-        cause: new Error(str)
+  throw new Error("Failure", {
+        cause: {
+          RE_EXN_ID: "Failure",
+          _1: str
+        }
       });
 }
 
-function raiseEvalError(str) {
-  throw new Error(new EvalError(str).RE_EXN_ID, {
-        cause: new EvalError(str)
-      });
-}
-
-function raiseRangeError(str) {
-  throw new Error(new RangeError(str).RE_EXN_ID, {
-        cause: new RangeError(str)
-      });
-}
-
-function raiseReferenceError(str) {
-  throw new Error(new ReferenceError(str).RE_EXN_ID, {
-        cause: new ReferenceError(str)
-      });
-}
-
-function raiseSyntaxError(str) {
-  throw new Error(new SyntaxError(str).RE_EXN_ID, {
-        cause: new SyntaxError(str)
-      });
-}
-
-function raiseTypeError(str) {
-  throw new Error(new TypeError(str).RE_EXN_ID, {
-        cause: new TypeError(str)
-      });
-}
-
-function raiseUriError(str) {
-  throw new Error(new URIError(str).RE_EXN_ID, {
-        cause: new URIError(str)
-      });
-}
-
-let $$Error$1 = "JsError";
+let $$Error = "JsError";
 
-exports.$$Error = $$Error$1;
+exports.$$Error = $$Error;
 exports.raiseError = raiseError;
-exports.raiseEvalError = raiseEvalError;
-exports.raiseRangeError = raiseRangeError;
-exports.raiseReferenceError = raiseReferenceError;
-exports.raiseSyntaxError = raiseSyntaxError;
-exports.raiseTypeError = raiseTypeError;
-exports.raiseUriError = raiseUriError;
 /* No side effect */
diff --git a/lib/js/js_null.js b/lib/js/js_null.js
index 73f42da3cf..8a2feb4283 100644
--- a/lib/js/js_null.js
+++ b/lib/js/js_null.js
@@ -10,8 +10,11 @@ function getExn(f) {
   if (f !== null) {
     return f;
   }
-  throw new Error(new Error("Js.Null.getExn").RE_EXN_ID, {
-        cause: new Error("Js.Null.getExn")
+  throw new Error("Failure", {
+        cause: {
+          RE_EXN_ID: "Failure",
+          _1: "Js.Null.getExn"
+        }
       });
 }
 
diff --git a/lib/js/js_option.js b/lib/js/js_option.js
index bdd59b6389..618c4816fb 100644
--- a/lib/js/js_option.js
+++ b/lib/js/js_option.js
@@ -26,8 +26,11 @@ function getExn(x) {
   if (x !== undefined) {
     return Caml_option.valFromOption(x);
   }
-  throw new Error(new Error("getExn").RE_EXN_ID, {
-        cause: new Error("getExn")
+  throw new Error("Failure", {
+        cause: {
+          RE_EXN_ID: "Failure",
+          _1: "getExn"
+        }
       });
 }
 
diff --git a/lib/js/js_undefined.js b/lib/js/js_undefined.js
index fcbfb19305..14e5c60208 100644
--- a/lib/js/js_undefined.js
+++ b/lib/js/js_undefined.js
@@ -14,8 +14,11 @@ function getExn(f) {
   if (f !== undefined) {
     return f;
   }
-  throw new Error(new Error("Js.Undefined.getExn").RE_EXN_ID, {
-        cause: new Error("Js.Undefined.getExn")
+  throw new Error("Failure", {
+        cause: {
+          RE_EXN_ID: "Failure",
+          _1: "Js.Undefined.getExn"
+        }
       });
 }
 

From a3a6a9c9a01dae42a80f8ad5f40207deb20eb744 Mon Sep 17 00:00:00 2001
From: Pedro Castro <aspeddro@gmail.com>
Date: Sat, 3 Aug 2024 21:39:28 -0300
Subject: [PATCH 2/6] remove comments

---
 jscomp/others/js_exn.res  | 46 ---------------------------------------
 jscomp/others/js_exn.resi |  6 -----
 2 files changed, 52 deletions(-)

diff --git a/jscomp/others/js_exn.res b/jscomp/others/js_exn.res
index fa33fac537..adde0715a6 100644
--- a/jscomp/others/js_exn.res
+++ b/jscomp/others/js_exn.res
@@ -34,54 +34,8 @@ external asJsExn: exn => option<t> = "?as_js_exn"
 @get external name: t => option<string> = "name"
 @get external fileName: t => option<string> = "fileName"
 
-// type error
-// @new external makeError: string => error = "Error"
 external isCamlExceptionOrOpenVariant: 'a => bool = "?is_extension"
 
 external anyToExnInternal: 'a => exn = "#wrap_exn"
 
 let raiseError = str => raise(Failure(str))
-
-// type eval_error
-// @new external makeEvalError: string => eval_error = "EvalError"
-//
-// let raiseEvalError = str => raise((Obj.magic((makeEvalError(str): eval_error)): exn))
-//
-// type range_error
-// @new external makeRangeError: string => range_error = "RangeError"
-//
-// let raiseRangeError = str => raise((Obj.magic((makeRangeError(str): range_error)): exn))
-//
-// type reference_error
-//
-// @new external makeReferenceError: string => reference_error = "ReferenceError"
-//
-// let raiseReferenceError = str => raise(Obj.magic(makeReferenceError(str)))
-//
-// type syntax_error
-// @new external makeSyntaxError: string => syntax_error = "SyntaxError"
-//
-// let raiseSyntaxError = str => raise(Obj.magic(makeSyntaxError(str)))
-//
-// type type_error
-// @new external makeTypeError: string => type_error = "TypeError"
-//
-// let raiseTypeError = str => raise(Obj.magic(makeTypeError(str)))
-//
-// type uri_error
-// @new external makeURIError: string => uri_error = "URIError"
-//
-// let raiseUriError = str => raise(Obj.magic(makeURIError(str)))
-
-/* TODO add predicate to tell which error is which " */
-
-/*
-exception EvalError of error
-exception RangeError of error
-exception ReferenceError of error
-exception SyntaxError of error
-exception TypeError of error
-
- The URIError object represents an error when a global URI handling function was used in a wrong way. 
-exception URIError of error    
-*/
diff --git a/jscomp/others/js_exn.resi b/jscomp/others/js_exn.resi
index e4faaa6be4..94e1680100 100644
--- a/jscomp/others/js_exn.resi
+++ b/jscomp/others/js_exn.resi
@@ -68,9 +68,3 @@ external anyToExnInternal: 'a => exn = "#wrap_exn"
 
 /** Raise Js exception Error object with stacktrace */
 let raiseError: string => 'a
-// let raiseEvalError: string => 'a
-// let raiseRangeError: string => 'a
-// let raiseReferenceError: string => 'a
-// let raiseSyntaxError: string => 'a
-// let raiseTypeError: string => 'a
-// let raiseUriError: string => 'a

From 286c097913ef69df7fb62ead8b604da0199aa1bb Mon Sep 17 00:00:00 2001
From: Pedro Castro <aspeddro@gmail.com>
Date: Sun, 4 Aug 2024 15:28:16 -0300
Subject: [PATCH 3/6] restore functions

---
 jscomp/others/js_exn.res            | 39 +++++++++++++++++++++++++++++
 jscomp/others/js_exn.resi           |  6 +++++
 jscomp/test/custom_error_test.js    |  2 +-
 jscomp/test/exception_value_test.js |  2 +-
 lib/es6/js_exn.js                   | 37 ++++++++++++++++++++++++++-
 lib/es6/js_null.js                  |  3 ++-
 lib/es6/js_option.js                |  3 ++-
 lib/es6/js_undefined.js             |  3 ++-
 lib/js/js_exn.js                    | 37 ++++++++++++++++++++++++++-
 lib/js/js_null.js                   |  3 ++-
 lib/js/js_option.js                 |  3 ++-
 lib/js/js_undefined.js              |  3 ++-
 12 files changed, 131 insertions(+), 10 deletions(-)

diff --git a/jscomp/others/js_exn.res b/jscomp/others/js_exn.res
index adde0715a6..1272445283 100644
--- a/jscomp/others/js_exn.res
+++ b/jscomp/others/js_exn.res
@@ -38,4 +38,43 @@ external isCamlExceptionOrOpenVariant: 'a => bool = "?is_extension"
 
 external anyToExnInternal: 'a => exn = "#wrap_exn"
 
+%%raw("
+function raiseThrow(exn) {
+  throw exn
+}
+")
+
+external raiseThrow: exn => 'a = "raiseThrow"
+
+type eval_error
+@new external makeEvalError: string => eval_error = "EvalError"
+
+let raiseEvalError = str => raiseThrow((Obj.magic((makeEvalError(str): eval_error)): exn))
+
+type range_error
+@new external makeRangeError: string => range_error = "RangeError"
+
+let raiseRangeError = str => raiseThrow((Obj.magic((makeRangeError(str): range_error)): exn))
+
+type reference_error
+
+@new external makeReferenceError: string => reference_error = "ReferenceError"
+
+let raiseReferenceError = str => raiseThrow(Obj.magic(makeReferenceError(str)))
+
+type syntax_error
+@new external makeSyntaxError: string => syntax_error = "SyntaxError"
+
+let raiseSyntaxError = str => raiseThrow(Obj.magic(makeSyntaxError(str)))
+
+type type_error
+@new external makeTypeError: string => type_error = "TypeError"
+
+let raiseTypeError = str => raiseThrow(Obj.magic(makeTypeError(str)))
+
+type uri_error
+@new external makeURIError: string => uri_error = "URIError"
+
+let raiseUriError = str => raiseThrow(Obj.magic(makeURIError(str)))
+
 let raiseError = str => raise(Failure(str))
diff --git a/jscomp/others/js_exn.resi b/jscomp/others/js_exn.resi
index 94e1680100..87ce8ca887 100644
--- a/jscomp/others/js_exn.resi
+++ b/jscomp/others/js_exn.resi
@@ -68,3 +68,9 @@ external anyToExnInternal: 'a => exn = "#wrap_exn"
 
 /** Raise Js exception Error object with stacktrace */
 let raiseError: string => 'a
+let raiseEvalError: string => 'a
+let raiseRangeError: string => 'a
+let raiseReferenceError: string => 'a
+let raiseSyntaxError: string => 'a
+let raiseTypeError: string => 'a
+let raiseUriError: string => 'a
diff --git a/jscomp/test/custom_error_test.js b/jscomp/test/custom_error_test.js
index e126b6f346..f9aaef1012 100644
--- a/jscomp/test/custom_error_test.js
+++ b/jscomp/test/custom_error_test.js
@@ -77,4 +77,4 @@ exports.test_js_error = test_js_error;
 exports.test_js_error2 = test_js_error2;
 exports.example1 = example1;
 exports.example2 = example2;
-/* No side effect */
+/* Js_exn Not a pure module */
diff --git a/jscomp/test/exception_value_test.js b/jscomp/test/exception_value_test.js
index a48c45483f..ce23e4e0f0 100644
--- a/jscomp/test/exception_value_test.js
+++ b/jscomp/test/exception_value_test.js
@@ -101,4 +101,4 @@ exports.u = u;
 exports.test_not_found = test_not_found;
 exports.test_js_error2 = test_js_error2;
 exports.test_js_error3 = test_js_error3;
-/* No side effect */
+/* Js_exn Not a pure module */
diff --git a/lib/es6/js_exn.js b/lib/es6/js_exn.js
index 175a30d196..75dfdd3bf7 100644
--- a/lib/es6/js_exn.js
+++ b/lib/es6/js_exn.js
@@ -1,6 +1,35 @@
 
 
 
+function raiseThrow(exn) {
+  throw exn
+}
+;
+
+function raiseEvalError(str) {
+  return raiseThrow(new EvalError(str));
+}
+
+function raiseRangeError(str) {
+  return raiseThrow(new RangeError(str));
+}
+
+function raiseReferenceError(str) {
+  return raiseThrow(new ReferenceError(str));
+}
+
+function raiseSyntaxError(str) {
+  return raiseThrow(new SyntaxError(str));
+}
+
+function raiseTypeError(str) {
+  return raiseThrow(new TypeError(str));
+}
+
+function raiseUriError(str) {
+  return raiseThrow(new URIError(str));
+}
+
 function raiseError(str) {
   throw new Error("Failure", {
         cause: {
@@ -15,5 +44,11 @@ let $$Error = "JsError";
 export {
   $$Error,
   raiseError,
+  raiseEvalError,
+  raiseRangeError,
+  raiseReferenceError,
+  raiseSyntaxError,
+  raiseTypeError,
+  raiseUriError,
 }
-/* No side effect */
+/*  Not a pure module */
diff --git a/lib/es6/js_null.js b/lib/es6/js_null.js
index 72a8bdcbc6..d48da94bab 100644
--- a/lib/es6/js_null.js
+++ b/lib/es6/js_null.js
@@ -1,5 +1,6 @@
 
 
+import * as Js_exn from "./js_exn.js";
 import * as Caml_option from "./caml_option.js";
 
 function test(x) {
@@ -51,4 +52,4 @@ export {
   fromOption,
   from_opt,
 }
-/* No side effect */
+/* Js_exn Not a pure module */
diff --git a/lib/es6/js_option.js b/lib/es6/js_option.js
index be8043e118..2fb01779c5 100644
--- a/lib/es6/js_option.js
+++ b/lib/es6/js_option.js
@@ -1,5 +1,6 @@
 
 
+import * as Js_exn from "./js_exn.js";
 import * as Caml_option from "./caml_option.js";
 
 function some(x) {
@@ -105,4 +106,4 @@ export {
   filter,
   firstSome,
 }
-/* No side effect */
+/* Js_exn Not a pure module */
diff --git a/lib/es6/js_undefined.js b/lib/es6/js_undefined.js
index 4f20b8854a..37455789d2 100644
--- a/lib/es6/js_undefined.js
+++ b/lib/es6/js_undefined.js
@@ -1,5 +1,6 @@
 
 
+import * as Js_exn from "./js_exn.js";
 import * as Caml_option from "./caml_option.js";
 
 function test(x) {
@@ -54,4 +55,4 @@ export {
   fromOption,
   from_opt,
 }
-/* No side effect */
+/* Js_exn Not a pure module */
diff --git a/lib/js/js_exn.js b/lib/js/js_exn.js
index 5a44ef3060..d48f2d4cef 100644
--- a/lib/js/js_exn.js
+++ b/lib/js/js_exn.js
@@ -1,6 +1,35 @@
 'use strict';
 
 
+function raiseThrow(exn) {
+  throw exn
+}
+;
+
+function raiseEvalError(str) {
+  return raiseThrow(new EvalError(str));
+}
+
+function raiseRangeError(str) {
+  return raiseThrow(new RangeError(str));
+}
+
+function raiseReferenceError(str) {
+  return raiseThrow(new ReferenceError(str));
+}
+
+function raiseSyntaxError(str) {
+  return raiseThrow(new SyntaxError(str));
+}
+
+function raiseTypeError(str) {
+  return raiseThrow(new TypeError(str));
+}
+
+function raiseUriError(str) {
+  return raiseThrow(new URIError(str));
+}
+
 function raiseError(str) {
   throw new Error("Failure", {
         cause: {
@@ -14,4 +43,10 @@ let $$Error = "JsError";
 
 exports.$$Error = $$Error;
 exports.raiseError = raiseError;
-/* No side effect */
+exports.raiseEvalError = raiseEvalError;
+exports.raiseRangeError = raiseRangeError;
+exports.raiseReferenceError = raiseReferenceError;
+exports.raiseSyntaxError = raiseSyntaxError;
+exports.raiseTypeError = raiseTypeError;
+exports.raiseUriError = raiseUriError;
+/*  Not a pure module */
diff --git a/lib/js/js_null.js b/lib/js/js_null.js
index 8a2feb4283..44857e4ad5 100644
--- a/lib/js/js_null.js
+++ b/lib/js/js_null.js
@@ -1,5 +1,6 @@
 'use strict';
 
+let Js_exn = require("./js_exn.js");
 let Caml_option = require("./caml_option.js");
 
 function test(x) {
@@ -49,4 +50,4 @@ exports.bind = bind;
 exports.iter = iter;
 exports.fromOption = fromOption;
 exports.from_opt = from_opt;
-/* No side effect */
+/* Js_exn Not a pure module */
diff --git a/lib/js/js_option.js b/lib/js/js_option.js
index 618c4816fb..5408a24cbe 100644
--- a/lib/js/js_option.js
+++ b/lib/js/js_option.js
@@ -1,5 +1,6 @@
 'use strict';
 
+let Js_exn = require("./js_exn.js");
 let Caml_option = require("./caml_option.js");
 
 function some(x) {
@@ -104,4 +105,4 @@ exports.default = $$default;
 exports.__esModule = true;
 exports.filter = filter;
 exports.firstSome = firstSome;
-/* No side effect */
+/* Js_exn Not a pure module */
diff --git a/lib/js/js_undefined.js b/lib/js/js_undefined.js
index 14e5c60208..c84ece9f56 100644
--- a/lib/js/js_undefined.js
+++ b/lib/js/js_undefined.js
@@ -1,5 +1,6 @@
 'use strict';
 
+let Js_exn = require("./js_exn.js");
 let Caml_option = require("./caml_option.js");
 
 function test(x) {
@@ -52,4 +53,4 @@ exports.bind = bind;
 exports.iter = iter;
 exports.fromOption = fromOption;
 exports.from_opt = from_opt;
-/* No side effect */
+/* Js_exn Not a pure module */

From 18fcf854e60206b99e511abe01027f23aade63af Mon Sep 17 00:00:00 2001
From: Pedro Castro <aspeddro@gmail.com>
Date: Sun, 4 Aug 2024 15:33:29 -0300
Subject: [PATCH 4/6] sync with master

---
 jscomp/test/js_exception_catch_test.js | 11 +++++---
 lib/es6/js_exn.js                      | 37 +++++++++++---------------
 lib/es6/js_null.js                     |  7 +++--
 lib/es6/js_option.js                   |  7 +++--
 lib/es6/js_undefined.js                |  7 +++--
 lib/js/js_exn.js                       | 37 +++++++++++---------------
 lib/js/js_null.js                      |  7 +++--
 lib/js/js_option.js                    |  7 +++--
 lib/js/js_undefined.js                 |  7 +++--
 9 files changed, 69 insertions(+), 58 deletions(-)

diff --git a/jscomp/test/js_exception_catch_test.js b/jscomp/test/js_exception_catch_test.js
index 633879ce73..a93a2e8fc3 100644
--- a/jscomp/test/js_exception_catch_test.js
+++ b/jscomp/test/js_exception_catch_test.js
@@ -205,10 +205,13 @@ eq("File \"js_exception_catch_test.res\", line 52, characters 5-12", test(functi
 }), "C_any");
 
 eq("File \"js_exception_catch_test.res\", line 53, characters 5-12", test(function () {
-  throw new Error(new Error("x").RE_EXN_ID, {
-    cause: new Error("x")
+  throw new Error("Failure", {
+    cause: {
+      RE_EXN_ID: "Failure",
+      _1: "x"
+    }
   });
-}), "Js_error");
+}), "Failure");
 
 eq("File \"js_exception_catch_test.res\", line 54, characters 5-12", test(function () {
   throw new Error("Failure", {
@@ -217,7 +220,7 @@ eq("File \"js_exception_catch_test.res\", line 54, characters 5-12", test(functi
       _1: "x"
     }
   });
-}), "Any");
+}), "Failure");
 
 Mt.from_pair_suites("Js_exception_catch_test", suites.contents);
 
diff --git a/lib/es6/js_exn.js b/lib/es6/js_exn.js
index d0b17a62a0..1e5b0849ac 100644
--- a/lib/es6/js_exn.js
+++ b/lib/es6/js_exn.js
@@ -1,46 +1,41 @@
 
 
 
-function raiseError(str) {
-  throw new Error(new Error(str).RE_EXN_ID, {
-    cause: new Error(str)
-  });
+function raiseThrow(exn) {
+  throw exn
 }
 ;
 
 function raiseEvalError(str) {
-  throw new Error(new EvalError(str).RE_EXN_ID, {
-    cause: new EvalError(str)
-  });
+  return raiseThrow(new EvalError(str));
 }
 
 function raiseRangeError(str) {
-  throw new Error(new RangeError(str).RE_EXN_ID, {
-    cause: new RangeError(str)
-  });
+  return raiseThrow(new RangeError(str));
 }
 
 function raiseReferenceError(str) {
-  throw new Error(new ReferenceError(str).RE_EXN_ID, {
-    cause: new ReferenceError(str)
-  });
+  return raiseThrow(new ReferenceError(str));
 }
 
 function raiseSyntaxError(str) {
-  throw new Error(new SyntaxError(str).RE_EXN_ID, {
-    cause: new SyntaxError(str)
-  });
+  return raiseThrow(new SyntaxError(str));
 }
 
 function raiseTypeError(str) {
-  throw new Error(new TypeError(str).RE_EXN_ID, {
-    cause: new TypeError(str)
-  });
+  return raiseThrow(new TypeError(str));
 }
 
 function raiseUriError(str) {
-  throw new Error(new URIError(str).RE_EXN_ID, {
-    cause: new URIError(str)
+  return raiseThrow(new URIError(str));
+}
+
+function raiseError(str) {
+  throw new Error("Failure", {
+    cause: {
+      RE_EXN_ID: "Failure",
+      _1: str
+    }
   });
 }
 
diff --git a/lib/es6/js_null.js b/lib/es6/js_null.js
index d41b8db9de..db8290b11b 100644
--- a/lib/es6/js_null.js
+++ b/lib/es6/js_null.js
@@ -11,8 +11,11 @@ function getExn(f) {
   if (f !== null) {
     return f;
   }
-  throw new Error(new Error("Js.Null.getExn").RE_EXN_ID, {
-    cause: new Error("Js.Null.getExn")
+  throw new Error("Failure", {
+    cause: {
+      RE_EXN_ID: "Failure",
+      _1: "Js.Null.getExn"
+    }
   });
 }
 
diff --git a/lib/es6/js_option.js b/lib/es6/js_option.js
index 4834310475..f438918014 100644
--- a/lib/es6/js_option.js
+++ b/lib/es6/js_option.js
@@ -27,8 +27,11 @@ function getExn(x) {
   if (x !== undefined) {
     return Caml_option.valFromOption(x);
   }
-  throw new Error(new Error("getExn").RE_EXN_ID, {
-    cause: new Error("getExn")
+  throw new Error("Failure", {
+    cause: {
+      RE_EXN_ID: "Failure",
+      _1: "getExn"
+    }
   });
 }
 
diff --git a/lib/es6/js_undefined.js b/lib/es6/js_undefined.js
index 7beab698eb..43b932b678 100644
--- a/lib/es6/js_undefined.js
+++ b/lib/es6/js_undefined.js
@@ -15,8 +15,11 @@ function getExn(f) {
   if (f !== undefined) {
     return f;
   }
-  throw new Error(new Error("Js.Undefined.getExn").RE_EXN_ID, {
-    cause: new Error("Js.Undefined.getExn")
+  throw new Error("Failure", {
+    cause: {
+      RE_EXN_ID: "Failure",
+      _1: "Js.Undefined.getExn"
+    }
   });
 }
 
diff --git a/lib/js/js_exn.js b/lib/js/js_exn.js
index 38639d520b..7c54fc5aac 100644
--- a/lib/js/js_exn.js
+++ b/lib/js/js_exn.js
@@ -1,46 +1,41 @@
 'use strict';
 
 
-function raiseError(str) {
-  throw new Error(new Error(str).RE_EXN_ID, {
-    cause: new Error(str)
-  });
+function raiseThrow(exn) {
+  throw exn
 }
 ;
 
 function raiseEvalError(str) {
-  throw new Error(new EvalError(str).RE_EXN_ID, {
-    cause: new EvalError(str)
-  });
+  return raiseThrow(new EvalError(str));
 }
 
 function raiseRangeError(str) {
-  throw new Error(new RangeError(str).RE_EXN_ID, {
-    cause: new RangeError(str)
-  });
+  return raiseThrow(new RangeError(str));
 }
 
 function raiseReferenceError(str) {
-  throw new Error(new ReferenceError(str).RE_EXN_ID, {
-    cause: new ReferenceError(str)
-  });
+  return raiseThrow(new ReferenceError(str));
 }
 
 function raiseSyntaxError(str) {
-  throw new Error(new SyntaxError(str).RE_EXN_ID, {
-    cause: new SyntaxError(str)
-  });
+  return raiseThrow(new SyntaxError(str));
 }
 
 function raiseTypeError(str) {
-  throw new Error(new TypeError(str).RE_EXN_ID, {
-    cause: new TypeError(str)
-  });
+  return raiseThrow(new TypeError(str));
 }
 
 function raiseUriError(str) {
-  throw new Error(new URIError(str).RE_EXN_ID, {
-    cause: new URIError(str)
+  return raiseThrow(new URIError(str));
+}
+
+function raiseError(str) {
+  throw new Error("Failure", {
+    cause: {
+      RE_EXN_ID: "Failure",
+      _1: str
+    }
   });
 }
 
diff --git a/lib/js/js_null.js b/lib/js/js_null.js
index f3ae2e1cb3..7c107acfcf 100644
--- a/lib/js/js_null.js
+++ b/lib/js/js_null.js
@@ -11,8 +11,11 @@ function getExn(f) {
   if (f !== null) {
     return f;
   }
-  throw new Error(new Error("Js.Null.getExn").RE_EXN_ID, {
-    cause: new Error("Js.Null.getExn")
+  throw new Error("Failure", {
+    cause: {
+      RE_EXN_ID: "Failure",
+      _1: "Js.Null.getExn"
+    }
   });
 }
 
diff --git a/lib/js/js_option.js b/lib/js/js_option.js
index 44fb25e18d..81bba10e49 100644
--- a/lib/js/js_option.js
+++ b/lib/js/js_option.js
@@ -27,8 +27,11 @@ function getExn(x) {
   if (x !== undefined) {
     return Caml_option.valFromOption(x);
   }
-  throw new Error(new Error("getExn").RE_EXN_ID, {
-    cause: new Error("getExn")
+  throw new Error("Failure", {
+    cause: {
+      RE_EXN_ID: "Failure",
+      _1: "getExn"
+    }
   });
 }
 
diff --git a/lib/js/js_undefined.js b/lib/js/js_undefined.js
index be406d0d1c..1dce2f33b3 100644
--- a/lib/js/js_undefined.js
+++ b/lib/js/js_undefined.js
@@ -15,8 +15,11 @@ function getExn(f) {
   if (f !== undefined) {
     return f;
   }
-  throw new Error(new Error("Js.Undefined.getExn").RE_EXN_ID, {
-    cause: new Error("Js.Undefined.getExn")
+  throw new Error("Failure", {
+    cause: {
+      RE_EXN_ID: "Failure",
+      _1: "Js.Undefined.getExn"
+    }
   });
 }
 

From 3ea3fbca966ffde4a40d7fa4512a1faed5f6eb0f Mon Sep 17 00:00:00 2001
From: Pedro Castro <aspeddro@gmail.com>
Date: Sun, 4 Aug 2024 15:57:28 -0300
Subject: [PATCH 5/6] polish

---
 jscomp/others/js_exn.res               | 38 +++++++++++++++++---------
 jscomp/test/custom_error_test.js       |  2 +-
 jscomp/test/exception_value_test.js    |  2 +-
 jscomp/test/js_exception_catch_test.js |  7 +----
 lib/es6/js_exn.js                      | 36 ++++++++++--------------
 lib/es6/js_null.js                     | 10 ++-----
 lib/es6/js_option.js                   | 10 ++-----
 lib/es6/js_undefined.js                | 10 ++-----
 lib/js/js_exn.js                       | 36 ++++++++++--------------
 lib/js/js_null.js                      | 10 ++-----
 lib/js/js_option.js                    | 10 ++-----
 lib/js/js_undefined.js                 | 10 ++-----
 12 files changed, 76 insertions(+), 105 deletions(-)

diff --git a/jscomp/others/js_exn.res b/jscomp/others/js_exn.res
index 1272445283..126c4b9cab 100644
--- a/jscomp/others/js_exn.res
+++ b/jscomp/others/js_exn.res
@@ -34,47 +34,59 @@ external asJsExn: exn => option<t> = "?as_js_exn"
 @get external name: t => option<string> = "name"
 @get external fileName: t => option<string> = "fileName"
 
+type error
+@new external makeError: string => error = "Error"
+
 external isCamlExceptionOrOpenVariant: 'a => bool = "?is_extension"
 
 external anyToExnInternal: 'a => exn = "#wrap_exn"
 
-%%raw("
-function raiseThrow(exn) {
-  throw exn
-}
-")
+let throw: exn => 'a = %raw("function (exn) {
+  throw exn;
+}")
 
-external raiseThrow: exn => 'a = "raiseThrow"
+let raiseError = str => throw((Obj.magic((makeError(str): error)): exn))
 
 type eval_error
 @new external makeEvalError: string => eval_error = "EvalError"
 
-let raiseEvalError = str => raiseThrow((Obj.magic((makeEvalError(str): eval_error)): exn))
+let raiseEvalError = str => throw((Obj.magic((makeEvalError(str): eval_error)): exn))
 
 type range_error
 @new external makeRangeError: string => range_error = "RangeError"
 
-let raiseRangeError = str => raiseThrow((Obj.magic((makeRangeError(str): range_error)): exn))
+let raiseRangeError = str => throw((Obj.magic((makeRangeError(str): range_error)): exn))
 
 type reference_error
 
 @new external makeReferenceError: string => reference_error = "ReferenceError"
 
-let raiseReferenceError = str => raiseThrow(Obj.magic(makeReferenceError(str)))
+let raiseReferenceError = str => throw(Obj.magic(makeReferenceError(str)))
 
 type syntax_error
 @new external makeSyntaxError: string => syntax_error = "SyntaxError"
 
-let raiseSyntaxError = str => raiseThrow(Obj.magic(makeSyntaxError(str)))
+let raiseSyntaxError = str => throw(Obj.magic(makeSyntaxError(str)))
 
 type type_error
 @new external makeTypeError: string => type_error = "TypeError"
 
-let raiseTypeError = str => raiseThrow(Obj.magic(makeTypeError(str)))
+let raiseTypeError = str => throw(Obj.magic(makeTypeError(str)))
 
 type uri_error
 @new external makeURIError: string => uri_error = "URIError"
 
-let raiseUriError = str => raiseThrow(Obj.magic(makeURIError(str)))
+let raiseUriError = str => throw(Obj.magic(makeURIError(str)))
+
+/* TODO add predicate to tell which error is which " */
+
+/*
+exception EvalError of error
+exception RangeError of error
+exception ReferenceError of error
+exception SyntaxError of error
+exception TypeError of error
 
-let raiseError = str => raise(Failure(str))
+ The URIError object represents an error when a global URI handling function was used in a wrong way. 
+exception URIError of error    
+*/
diff --git a/jscomp/test/custom_error_test.js b/jscomp/test/custom_error_test.js
index 066536f4b2..0e19bcac08 100644
--- a/jscomp/test/custom_error_test.js
+++ b/jscomp/test/custom_error_test.js
@@ -73,4 +73,4 @@ exports.test_js_error = test_js_error;
 exports.test_js_error2 = test_js_error2;
 exports.example1 = example1;
 exports.example2 = example2;
-/* Js_exn Not a pure module */
+/* No side effect */
diff --git a/jscomp/test/exception_value_test.js b/jscomp/test/exception_value_test.js
index 252974bc13..dee7400ffb 100644
--- a/jscomp/test/exception_value_test.js
+++ b/jscomp/test/exception_value_test.js
@@ -98,4 +98,4 @@ exports.u = u;
 exports.test_not_found = test_not_found;
 exports.test_js_error2 = test_js_error2;
 exports.test_js_error3 = test_js_error3;
-/* Js_exn Not a pure module */
+/* No side effect */
diff --git a/jscomp/test/js_exception_catch_test.js b/jscomp/test/js_exception_catch_test.js
index a93a2e8fc3..7d02ed92e3 100644
--- a/jscomp/test/js_exception_catch_test.js
+++ b/jscomp/test/js_exception_catch_test.js
@@ -205,12 +205,7 @@ eq("File \"js_exception_catch_test.res\", line 52, characters 5-12", test(functi
 }), "C_any");
 
 eq("File \"js_exception_catch_test.res\", line 53, characters 5-12", test(function () {
-  throw new Error("Failure", {
-    cause: {
-      RE_EXN_ID: "Failure",
-      _1: "x"
-    }
-  });
+  Js_exn.raiseError("x");
 }), "Failure");
 
 eq("File \"js_exception_catch_test.res\", line 54, characters 5-12", test(function () {
diff --git a/lib/es6/js_exn.js b/lib/es6/js_exn.js
index 1e5b0849ac..4eed951c5b 100644
--- a/lib/es6/js_exn.js
+++ b/lib/es6/js_exn.js
@@ -1,48 +1,42 @@
 
 
 
-function raiseThrow(exn) {
-  throw exn
+let $$throw = (function (exn) {
+  throw exn;
+});
+
+function raiseError(str) {
+  return $$throw(new Error(str));
 }
-;
 
 function raiseEvalError(str) {
-  return raiseThrow(new EvalError(str));
+  return $$throw(new EvalError(str));
 }
 
 function raiseRangeError(str) {
-  return raiseThrow(new RangeError(str));
+  return $$throw(new RangeError(str));
 }
 
 function raiseReferenceError(str) {
-  return raiseThrow(new ReferenceError(str));
+  return $$throw(new ReferenceError(str));
 }
 
 function raiseSyntaxError(str) {
-  return raiseThrow(new SyntaxError(str));
+  return $$throw(new SyntaxError(str));
 }
 
 function raiseTypeError(str) {
-  return raiseThrow(new TypeError(str));
+  return $$throw(new TypeError(str));
 }
 
 function raiseUriError(str) {
-  return raiseThrow(new URIError(str));
-}
-
-function raiseError(str) {
-  throw new Error("Failure", {
-    cause: {
-      RE_EXN_ID: "Failure",
-      _1: str
-    }
-  });
+  return $$throw(new URIError(str));
 }
 
-let $$Error = "JsError";
+let $$Error$1 = "JsError";
 
 export {
-  $$Error,
+  $$Error$1 as $$Error,
   raiseError,
   raiseEvalError,
   raiseRangeError,
@@ -51,4 +45,4 @@ export {
   raiseTypeError,
   raiseUriError,
 }
-/*  Not a pure module */
+/* No side effect */
diff --git a/lib/es6/js_null.js b/lib/es6/js_null.js
index db8290b11b..fefa01beeb 100644
--- a/lib/es6/js_null.js
+++ b/lib/es6/js_null.js
@@ -10,13 +10,9 @@ function test(x) {
 function getExn(f) {
   if (f !== null) {
     return f;
+  } else {
+    return Js_exn.raiseError("Js.Null.getExn");
   }
-  throw new Error("Failure", {
-    cause: {
-      RE_EXN_ID: "Failure",
-      _1: "Js.Null.getExn"
-    }
-  });
 }
 
 function bind(x, f) {
@@ -52,4 +48,4 @@ export {
   fromOption,
   from_opt,
 }
-/* Js_exn Not a pure module */
+/* No side effect */
diff --git a/lib/es6/js_option.js b/lib/es6/js_option.js
index f438918014..b6807fa942 100644
--- a/lib/es6/js_option.js
+++ b/lib/es6/js_option.js
@@ -26,13 +26,9 @@ function isNone(x) {
 function getExn(x) {
   if (x !== undefined) {
     return Caml_option.valFromOption(x);
+  } else {
+    return Js_exn.raiseError("getExn");
   }
-  throw new Error("Failure", {
-    cause: {
-      RE_EXN_ID: "Failure",
-      _1: "getExn"
-    }
-  });
 }
 
 function equal(eq, a, b) {
@@ -106,4 +102,4 @@ export {
   filter,
   firstSome,
 }
-/* Js_exn Not a pure module */
+/* No side effect */
diff --git a/lib/es6/js_undefined.js b/lib/es6/js_undefined.js
index 43b932b678..cb07253b25 100644
--- a/lib/es6/js_undefined.js
+++ b/lib/es6/js_undefined.js
@@ -14,13 +14,9 @@ function testAny(x) {
 function getExn(f) {
   if (f !== undefined) {
     return f;
+  } else {
+    return Js_exn.raiseError("Js.Undefined.getExn");
   }
-  throw new Error("Failure", {
-    cause: {
-      RE_EXN_ID: "Failure",
-      _1: "Js.Undefined.getExn"
-    }
-  });
 }
 
 function bind(x, f) {
@@ -55,4 +51,4 @@ export {
   fromOption,
   from_opt,
 }
-/* Js_exn Not a pure module */
+/* No side effect */
diff --git a/lib/js/js_exn.js b/lib/js/js_exn.js
index 7c54fc5aac..4b4c9883bf 100644
--- a/lib/js/js_exn.js
+++ b/lib/js/js_exn.js
@@ -1,47 +1,41 @@
 'use strict';
 
 
-function raiseThrow(exn) {
-  throw exn
+let $$throw = (function (exn) {
+  throw exn;
+});
+
+function raiseError(str) {
+  return $$throw(new Error(str));
 }
-;
 
 function raiseEvalError(str) {
-  return raiseThrow(new EvalError(str));
+  return $$throw(new EvalError(str));
 }
 
 function raiseRangeError(str) {
-  return raiseThrow(new RangeError(str));
+  return $$throw(new RangeError(str));
 }
 
 function raiseReferenceError(str) {
-  return raiseThrow(new ReferenceError(str));
+  return $$throw(new ReferenceError(str));
 }
 
 function raiseSyntaxError(str) {
-  return raiseThrow(new SyntaxError(str));
+  return $$throw(new SyntaxError(str));
 }
 
 function raiseTypeError(str) {
-  return raiseThrow(new TypeError(str));
+  return $$throw(new TypeError(str));
 }
 
 function raiseUriError(str) {
-  return raiseThrow(new URIError(str));
-}
-
-function raiseError(str) {
-  throw new Error("Failure", {
-    cause: {
-      RE_EXN_ID: "Failure",
-      _1: str
-    }
-  });
+  return $$throw(new URIError(str));
 }
 
-let $$Error = "JsError";
+let $$Error$1 = "JsError";
 
-exports.$$Error = $$Error;
+exports.$$Error = $$Error$1;
 exports.raiseError = raiseError;
 exports.raiseEvalError = raiseEvalError;
 exports.raiseRangeError = raiseRangeError;
@@ -49,4 +43,4 @@ exports.raiseReferenceError = raiseReferenceError;
 exports.raiseSyntaxError = raiseSyntaxError;
 exports.raiseTypeError = raiseTypeError;
 exports.raiseUriError = raiseUriError;
-/*  Not a pure module */
+/* No side effect */
diff --git a/lib/js/js_null.js b/lib/js/js_null.js
index 7c107acfcf..cd3023dca0 100644
--- a/lib/js/js_null.js
+++ b/lib/js/js_null.js
@@ -10,13 +10,9 @@ function test(x) {
 function getExn(f) {
   if (f !== null) {
     return f;
+  } else {
+    return Js_exn.raiseError("Js.Null.getExn");
   }
-  throw new Error("Failure", {
-    cause: {
-      RE_EXN_ID: "Failure",
-      _1: "Js.Null.getExn"
-    }
-  });
 }
 
 function bind(x, f) {
@@ -50,4 +46,4 @@ exports.bind = bind;
 exports.iter = iter;
 exports.fromOption = fromOption;
 exports.from_opt = from_opt;
-/* Js_exn Not a pure module */
+/* No side effect */
diff --git a/lib/js/js_option.js b/lib/js/js_option.js
index 81bba10e49..3d7e188ed4 100644
--- a/lib/js/js_option.js
+++ b/lib/js/js_option.js
@@ -26,13 +26,9 @@ function isNone(x) {
 function getExn(x) {
   if (x !== undefined) {
     return Caml_option.valFromOption(x);
+  } else {
+    return Js_exn.raiseError("getExn");
   }
-  throw new Error("Failure", {
-    cause: {
-      RE_EXN_ID: "Failure",
-      _1: "getExn"
-    }
-  });
 }
 
 function equal(eq, a, b) {
@@ -105,4 +101,4 @@ exports.default = $$default;
 exports.__esModule = true;
 exports.filter = filter;
 exports.firstSome = firstSome;
-/* Js_exn Not a pure module */
+/* No side effect */
diff --git a/lib/js/js_undefined.js b/lib/js/js_undefined.js
index 1dce2f33b3..9de3e4cb45 100644
--- a/lib/js/js_undefined.js
+++ b/lib/js/js_undefined.js
@@ -14,13 +14,9 @@ function testAny(x) {
 function getExn(f) {
   if (f !== undefined) {
     return f;
+  } else {
+    return Js_exn.raiseError("Js.Undefined.getExn");
   }
-  throw new Error("Failure", {
-    cause: {
-      RE_EXN_ID: "Failure",
-      _1: "Js.Undefined.getExn"
-    }
-  });
 }
 
 function bind(x, f) {
@@ -53,4 +49,4 @@ exports.bind = bind;
 exports.iter = iter;
 exports.fromOption = fromOption;
 exports.from_opt = from_opt;
-/* Js_exn Not a pure module */
+/* No side effect */

From 9d351efb99702befbc270fed4371e9d5a7a0d7e6 Mon Sep 17 00:00:00 2001
From: Pedro Castro <aspeddro@gmail.com>
Date: Sun, 4 Aug 2024 16:02:21 -0300
Subject: [PATCH 6/6] fix tests

---
 jscomp/test/js_exception_catch_test.js  | 8 ++++----
 jscomp/test/js_exception_catch_test.res | 6 +++---
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/jscomp/test/js_exception_catch_test.js b/jscomp/test/js_exception_catch_test.js
index 7d02ed92e3..756dab19be 100644
--- a/jscomp/test/js_exception_catch_test.js
+++ b/jscomp/test/js_exception_catch_test.js
@@ -120,8 +120,8 @@ function test(f) {
       } else {
         return "C";
       }
-    } else if (e.RE_EXN_ID === "Failure") {
-      return "Failure";
+    } else if (e.RE_EXN_ID === Js_exn.$$Error) {
+      return "Js_error";
     } else {
       return "Any";
     }
@@ -206,7 +206,7 @@ eq("File \"js_exception_catch_test.res\", line 52, characters 5-12", test(functi
 
 eq("File \"js_exception_catch_test.res\", line 53, characters 5-12", test(function () {
   Js_exn.raiseError("x");
-}), "Failure");
+}), "Js_error");
 
 eq("File \"js_exception_catch_test.res\", line 54, characters 5-12", test(function () {
   throw new Error("Failure", {
@@ -215,7 +215,7 @@ eq("File \"js_exception_catch_test.res\", line 54, characters 5-12", test(functi
       _1: "x"
     }
   });
-}), "Failure");
+}), "Any");
 
 Mt.from_pair_suites("Js_exception_catch_test", suites.contents);
 
diff --git a/jscomp/test/js_exception_catch_test.res b/jscomp/test/js_exception_catch_test.res
index 81d0a96c34..899a4f84f2 100644
--- a/jscomp/test/js_exception_catch_test.res
+++ b/jscomp/test/js_exception_catch_test.res
@@ -36,7 +36,7 @@ let test = f =>
   | B => #B
   | C(1, 2) => #C
   | C(_) => #C_any
-  | Failure(_) => #Failure
+  | Js.Exn.Error(_) => #Js_error
   | e => #Any
   }
 
@@ -50,8 +50,8 @@ let () = {
   eq(__LOC__, test(_ => raise(B)), #B)
   eq(__LOC__, test(_ => raise(C(1, 2))), #C)
   eq(__LOC__, test(_ => raise(C(0, 2))), #C_any)
-  eq(__LOC__, test(_ => Js.Exn.raiseError("x")), #Failure)
-  eq(__LOC__, test(_ => failwith("x")), #Failure)
+  eq(__LOC__, test(_ => Js.Exn.raiseError("x")), #Js_error)
+  eq(__LOC__, test(_ => failwith("x")), #Any)
 }
 
 let () = Mt.from_pair_suites(__MODULE__, suites.contents)