rescript-lang / rescript-lang/rescript-lang.org
Document exception handling for thrown non-Error values
Nobody has claimed this yet.
- Dominant language
- MDX
- Stars
- 1.9k
- Forks
- 260
- Avg merge
- 3d 9h
- Merged PRs (30d)
- 17
Description
This might be an interesting interop related use-case that is not covered in the docs yet:
let throwPlainValue: unit => unit = %raw(`
function() {
throw "test"
}
`)
try {
throwPlainValue()
} catch {
| Js.Exn.Error(obj) =>
switch Js.Exn.message(obj) {
| Some(m) => Js.log("Caught a JS exception! Message: " ++ m)
| None => Js.log2("probably not an error object", obj) // <-- we will hit this case here
}
}
In the example above, obj doesn't necessarily mean it's a Error, and ReScript doesn't do any special convertion to make it an Error. So in the None case, the user needs to figure out themselves what kind of value they are dealing with.
This might be problematic in situations where you are e.g. using some library that defines its own weird throwing system (not throwing error, but e.g. plain objects), and need to interact with the value.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the ReScript and JavaScript interop example in the issue, then locate the existing exception-handling documentation. Document that thrown values may be non-Error values and explain the handling shown by the example; done means this interop case is covered clearly for users.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100