Skip to content

Commit

Permalink
feat(error/expect): use panic instead of raising Failure
Browse files Browse the repository at this point in the history
  • Loading branch information
glennsl committed Mar 7, 2023
1 parent 8b198d5 commit 9280051
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
8 changes: 3 additions & 5 deletions src/Core__Option.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import * as Curry from "rescript/lib/es6/curry.js";
import * as Caml_option from "rescript/lib/es6/caml_option.js";
import * as Core__Error from "./Core__Error.mjs";

function flat(opt) {
if (opt !== undefined) {
Expand Down Expand Up @@ -39,12 +40,9 @@ function getExn(opt) {
function expect(opt, message) {
if (opt !== undefined) {
return Caml_option.valFromOption(opt);
} else {
return Core__Error.panic(message);
}
throw {
RE_EXN_ID: "Failure",
_1: message,
Error: new Error()
};
}

function mapWithDefault(opt, $$default, f) {
Expand Down
2 changes: 1 addition & 1 deletion src/Core__Option.res
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ let getExn = opt =>
let expect = (opt, message) =>
switch opt {
| Some(value) => value
| None => raise(Failure(message))
| None => Core__Error.panic(message)
}

external getUnsafe: option<'a> => 'a = "%identity"
Expand Down
2 changes: 1 addition & 1 deletion src/Core__Option.resi
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Option.expect(None, "should not be None") // Raises `Failure("should not be None

## Exceptions

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

Expand Down

0 comments on commit 9280051

Please sign in to comment.