Skip to content

Commit 50aef14

Browse files
Format
1 parent 889b8bc commit 50aef14

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

markdown-pages/blog/release-12-0-0.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,29 @@ The deprecated `*Exn` variants remain available in v12 to ease the transition, a
5050
Note that `Result.getOrThrow` now throws a JavaScript exception, so please update any exception-handling logic that relied on OCaml exception names. We also revamped the API around JS exceptions and errors.
5151

5252
We’ve renamed JS errors to `JsError.t` to better distinguish them from the `Result.Error` variant. Since JavaScript allows throwing anything (not only proper Error objects), the previous way of catching JS exceptions was unsafe:
53+
5354
```res
5455
let foo = switch myUnsafeJsResult() {
5556
| exception Exn.Error(e) => Error(e->Error.message)
5657
// ☝️ this will crash if `e` is undefined or null
5758
| myRes => Ok(myRes)
5859
}
5960
```
61+
6062
Additionally, the coexistence of `Result.Error` and the `Error` module caused confusion.
6163

6264
The new recommended pattern is:
65+
6366
```res
6467
let foo = switch myUnsafeJsResult() {
6568
| exception JsExn(e) => Error(e->JsExn.message))
6669
// ☝️ this is now safe even `e` is undefined or null
6770
| myRes => Ok(myRes)
6871
}
6972
```
73+
7074
Utility helpers for working with JS errors are now in `JsError`, eg:
75+
7176
```res
7277
JsError.throw(JsError.RangeError.make("the payload should be below 16"))
7378
```

0 commit comments

Comments
 (0)