diff --git a/ocaml-lsp-server/test/e2e-new/definition.ml b/ocaml-lsp-server/test/e2e-new/definition.ml index 72f9ffa57..1e049cb3e 100644 --- a/ocaml-lsp-server/test/e2e-new/definition.ml +++ b/ocaml-lsp-server/test/e2e-new/definition.ml @@ -2,6 +2,17 @@ open Test.Import let print_locations = Test.print_option Locations.yojson_of_t +let rec censor_backtraces = function + | `Assoc fields -> + `Assoc + (List.map fields ~f:(fun (name, value) -> + if String.equal name "backtrace" + then name, `String "" + else name, censor_backtraces value)) + | `List values -> `List (List.map values ~f:censor_backtraces) + | json -> json +;; + let definition client position = let textDocument = TextDocumentIdentifier.create ~uri:Helpers.uri in Client.request @@ -53,6 +64,32 @@ let%expect_test "reports definition lookup failures without stopping the server" |}] ;; +let%expect_test "definition of a nullary exception leaks Not_found" = + let source = "exception E\nE" in + Helpers.test source (fun client -> + let* result = + Fiber.collect_errors (fun () -> + definition client (Position.create ~line:1 ~character:1)) + in + match result with + | Error [ { Exn_with_backtrace.exn = Jsonrpc.Response.Error.E error; backtrace = _ } ] + -> + Jsonrpc.Response.Error.yojson_of_t error |> censor_backtraces |> Test.print_result; + Fiber.return () + | Error errors -> Fiber.reraise_all errors + | Ok response -> + print_locations response; + Fiber.return ()); + [%expect + {| + { + "data": { "exn": "Not_found", "backtrace": "" }, + "code": -32603, + "message": "uncaught exception" + } + |}] +;; + let%expect_test "returns location of a definition" = let source = {ocaml|let x = 43