Skip to content

Commit 9280051

Browse files
committed
feat(error/expect): use panic instead of raising Failure
1 parent 8b198d5 commit 9280051

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

src/Core__Option.mjs

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import * as Curry from "rescript/lib/es6/curry.js";
44
import * as Caml_option from "rescript/lib/es6/caml_option.js";
5+
import * as Core__Error from "./Core__Error.mjs";
56

67
function flat(opt) {
78
if (opt !== undefined) {
@@ -39,12 +40,9 @@ function getExn(opt) {
3940
function expect(opt, message) {
4041
if (opt !== undefined) {
4142
return Caml_option.valFromOption(opt);
43+
} else {
44+
return Core__Error.panic(message);
4245
}
43-
throw {
44-
RE_EXN_ID: "Failure",
45-
_1: message,
46-
Error: new Error()
47-
};
4846
}
4947

5048
function mapWithDefault(opt, $$default, f) {

src/Core__Option.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ let getExn = opt =>
5353
let expect = (opt, message) =>
5454
switch opt {
5555
| Some(value) => value
56-
| None => raise(Failure(message))
56+
| None => Core__Error.panic(message)
5757
}
5858

5959
external getUnsafe: option<'a> => 'a = "%identity"

src/Core__Option.resi

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ Option.expect(None, "should not be None") // Raises `Failure("should not be None
101101

102102
## Exceptions
103103

104-
- Raises `Failure` if `opt` is `None`
104+
- Panics if `opt` is `None`
105105
*/
106106
let expect: (option<'a>, string) => 'a
107107

0 commit comments

Comments
 (0)