rescript-vscode
rescript-vscode copied to clipboard
Code analysis gives warning when catching on exception from other module
Consider the following example:
module Test = {
exception Nested
@raises(Nested)
let raises = async () => raise(Nested)
}
let raises = async () =>
try await Test.raises() catch {
| Test.Nested => Js.log("Not found")
}
it gives me:
raises might raise Nested (test.res:9:12) and is not annotated with @raises(Nested)
However, if I open Test instead:
module Test = {
exception Nested
@raises(Nested)
let raises = async () => raise(Nested)
}
open Test
let raises = async () =>
try await Test.raises() catch {
| Nested => Js.log("Not found")
}
Everything works fine
Issue transferred from (https://github.com/rescript-association/reanalyze/issues/188)
I run into this issue too, when trying to centralize some error messages into a util module.
For a workaround, instead of opening the entire Util module you can alias the exception in an inner Exceptions module, and then open that
exception ResultError(string)
module Exceptions = {
exception ResultError = ResultError
}
@raises(ResultError)
let getOrRaise = result =>
switch result {
| Ok(value) => value
| Error(err) => raise(ResultError(err))
}
open Util.Exception
let do_ = async () => (...)