Skip to content

Commit 705c3af

Browse files
CopilotSimn
andcommitted
Fix overly-wide exception catches that swallow Cancelled and JsonCompleted
Co-authored-by: Simn <634365+Simn@users.noreply.github.com>
1 parent c12493a commit 705c3af

10 files changed

Lines changed: 28 additions & 15 deletions

File tree

src/compiler/compiler.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ with
447447
error com ("Error: No completion point was found") null_pos
448448
| DisplayException.DisplayException dex ->
449449
DisplayOutput.handle_display_exception com dex
450-
| CompilerMessage.Abort | Out_of_memory | EvalTypes.Sys_exit _ | Hlinterp.Sys_exit _ | DisplayJson.JsonCompleted as exc ->
450+
| CompilerMessage.Abort | Out_of_memory | EvalTypes.Sys_exit _ | Hlinterp.Sys_exit _ | DisplayJson.JsonCompleted | Globals.Cancelled as exc ->
451451
(* We don't want these to be caught by the catchall below *)
452452
raise exc
453453
| e when (try Sys.getenv "OCAMLRUNPARAM" <> "b" with _ -> true) && not Helper.is_debug_run ->

src/compiler/displayProcessing.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ let load_display_module_in_macro tctx display_file_dot_path clear = match displa
135135
let _ = MacroContext.load_macro_module (MacroContext.get_macro_context tctx) tctx.com cpath true p in
136136
Finalization.finalize mctx;
137137
Some mctx
138-
with DisplayException.DisplayException _ | Parser.TypePath _ as exc ->
138+
with DisplayException.DisplayException _ | Parser.TypePath _ | Globals.Cancelled | DisplayJson.JsonCompleted as exc ->
139139
raise exc
140140
| _ ->
141141
None

src/context/commonCache.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ class lib_build_task cs file ftime lib = object(self)
1515
try begin match lib#build path p with
1616
| Some r -> Hashtbl.add h path r
1717
| None -> ()
18-
end with _ ->
18+
end with Globals.Cancelled as e -> raise e
19+
| _ ->
1920
()
2021
end
2122
) lib#list_modules;

src/context/display/display.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,6 @@ let get_import_status ctx path =
9090
try
9191
let mt' = ctx.g.do_load_type_def ctx null_pos (mk_type_path ([],snd path)) in
9292
if path <> (t_infos mt').mt_path then Shadowed else Imported
93-
with _ ->
93+
with Globals.Cancelled as e -> raise e
94+
| _ ->
9495
Unimported

src/context/display/displayFields.ml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,8 @@ let handle_missing_field_raise ctx tthis i mode with_type pfield =
381381
begin try
382382
let e = type_expr ctx e WithType.value in
383383
e.etype
384-
with _ ->
384+
with Globals.Cancelled as e -> raise e
385+
| _ ->
385386
mk_mono()
386387
end
387388
| _ -> mk_mono()
@@ -393,7 +394,8 @@ let handle_missing_field_raise ctx tthis i mode with_type pfield =
393394
begin try
394395
let e = type_expr ctx e WithType.value in
395396
e.etype
396-
with _ ->
397+
with Globals.Cancelled as e -> raise e
398+
| _ ->
397399
raise Exit
398400
end
399401
| _ -> raise Exit
@@ -410,7 +412,8 @@ let handle_missing_field_raise ctx tthis i mode with_type pfield =
410412
(name,false,e.etype)
411413
) el in
412414
(TFun(tl,tret),Method MethNormal)
413-
with _ ->
415+
with Globals.Cancelled as e -> raise e
416+
| _ ->
414417
raise Exit
415418
end
416419
| MGet ->

src/context/display/displayPath.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ module TypePathHandler = struct
155155
) en.e_constrs fields
156156
in
157157
Some fields
158-
with _ ->
158+
with Globals.Cancelled | DisplayException.DisplayException _ | Parser.TypePath _ as e ->
159+
raise e
160+
| _ ->
159161
Error.abort ("Could not load module " ^ (s_type_path (p,c))) null_pos
160162
end
161163

src/context/display/displayToplevel.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ let maybe_resolve_macro_field ctx t c cf =
4949
let (tl,tr,c,cf) = ctx.g.do_load_macro ctx false c.cl_path cf.cf_name null_pos in
5050
let t = perform_type_voodoo t tl tr in
5151
t,{cf with cf_type = t}
52-
with _ ->
52+
with Globals.Cancelled as e -> raise e
53+
| _ ->
5354
t,cf
5455

5556
let exclude : string list ref = ref []
@@ -157,7 +158,7 @@ let init_or_update_server cs com timer_name =
157158
try
158159
ignore(cc#find_file file_key);
159160
with Not_found ->
160-
try ignore(TypeloadParse.parse_module_file com file_path null_pos) with _ -> ()
161+
try ignore(TypeloadParse.parse_module_file com file_path null_pos) with Globals.Cancelled as e -> raise e | _ -> ()
161162
) removed_files;
162163
DynArray.iter (Hashtbl.remove removed_files) removed_removed_files
163164

src/context/display/syntaxExplorer.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ let explore_uncached_modules tctx cs symbols =
179179
(* We have to flush immediately so we catch exceptions from weird modules *)
180180
Typecore.flush_pass tctx.g PFinal ("final",cfile.c_package @ [module_name]);
181181
m :: acc
182-
with _ ->
182+
with Globals.Cancelled as e -> raise e
183+
| _ ->
183184
acc
184185
end
185186
) files []

src/typing/macroContext.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ let make_macro_com_api com mcom p =
102102
match ParserEntry.parse_string (ParserConfig.default_config com.defines) Grammar.parse_meta s null_pos raise_typing_error false with
103103
| ParseSuccess(meta,_) -> meta
104104
| ParseError(_,_,_) -> raise_typing_error "Malformed metadata string" p
105-
with _ ->
105+
with Globals.Cancelled as e -> raise e
106+
| _ ->
106107
raise_typing_error "Malformed metadata string" p
107108
in
108109
let bad_stage () =
@@ -311,7 +312,8 @@ let make_macro_api ctx mctx p =
311312
match ParserEntry.parse_string (ParserConfig.default_config mctx.com.defines) Grammar.parse_meta s null_pos raise_typing_error false with
312313
| ParseSuccess(meta,_) -> meta
313314
| ParseError(_,_,_) -> raise_typing_error "Malformed metadata string" p
314-
with _ ->
315+
with Globals.Cancelled as e -> raise e
316+
| _ ->
315317
raise_typing_error "Malformed metadata string" p
316318
in
317319
let com_api = make_macro_com_api ctx.com mctx.com p in

src/typing/typerDisplay.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ let completion_item_of_expr ctx e =
2929
try
3030
let e' = type_expr ctx (EConst(Ident s),null_pos) (WithType.with_type t) in
3131
Texpr.equal e e'
32-
with _ ->
32+
with Globals.Cancelled as e -> raise e
33+
| _ ->
3334
false
3435
in
3536
let tpair ?(values=PMap.empty) t =
@@ -581,7 +582,8 @@ let filter_ctors ctx r =
581582
| _ -> false)
582583
| _ -> false
583584
end
584-
with _ ->
585+
with Globals.Cancelled as e -> raise e
586+
| _ ->
585587
false
586588
end
587589
end

0 commit comments

Comments
 (0)