Skip to content

Commit 2841ee9

Browse files
committed
Make convert function more error resilient (fixes Reason->Res unhandled exception bug)
1 parent 63670c0 commit 2841ee9

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

bindings/Bs_platform_api.re

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,22 @@ module Compiler = {
430430
// General format function
431431
let convertSyntax =
432432
(t, ~fromLang: Lang.t, ~toLang: Lang.t, ~code: string)
433-
: ConversionResult.t => {
434-
convertSyntax(t, Lang.toExt(fromLang), Lang.toExt(toLang), code)
435-
->ConversionResult.decode(~fromLang, ~toLang);
436-
};
433+
: ConversionResult.t =>
434+
435+
// TODO: There is an issue where trying to convert an empty Reason code
436+
// to ReScript code would throw an unhandled JSOO exception
437+
// we'd either need to special case the empty Reason code parsing,
438+
// or handle the error on the JSOO bundle side more gracefully
439+
try(
440+
convertSyntax(t, Lang.toExt(fromLang), Lang.toExt(toLang), code)
441+
->ConversionResult.decode(~fromLang, ~toLang)
442+
) {
443+
| Js.Exn.Error(obj) =>
444+
switch (Js.Exn.message(obj)) {
445+
| Some(m) => ConversionResult.UnexpectedError(m)
446+
| None => UnexpectedError("")
447+
}
448+
};
437449
};
438450

439451
[@bs.val] [@bs.scope "bs_platform"]

0 commit comments

Comments
 (0)