From 9280051282163546cbea1130cbd6b0c37083666c Mon Sep 17 00:00:00 2001 From: glennsl Date: Thu, 2 Mar 2023 11:02:18 +0100 Subject: [PATCH] feat(error/expect): use panic instead of raising Failure --- src/Core__Option.mjs | 8 +++----- src/Core__Option.res | 2 +- src/Core__Option.resi | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Core__Option.mjs b/src/Core__Option.mjs index 0b922916..d0679d4c 100644 --- a/src/Core__Option.mjs +++ b/src/Core__Option.mjs @@ -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) { @@ -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) { diff --git a/src/Core__Option.res b/src/Core__Option.res index 9d264bc6..726a074f 100644 --- a/src/Core__Option.res +++ b/src/Core__Option.res @@ -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" diff --git a/src/Core__Option.resi b/src/Core__Option.resi index 5a9a009b..2c1f2025 100644 --- a/src/Core__Option.resi +++ b/src/Core__Option.resi @@ -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