Skip to content

Commit

Permalink
fix exception handling in find-refs command
Browse files Browse the repository at this point in the history
Summary:
if i'm reading it correctly, if the server raises an exception during
`find-refs`, it writes to the server log and returns `None` which is not
marshaled over the channel so the client blocks until it times out.

instead, it should return an error to the user.

Reviewed By: avikchaudhuri

Differential Revision: D5088871

fbshipit-source-id: 35c4c629d1784b4b1f3a6890ddd6e77428b0aea3
  • Loading branch information
mroch authored and facebook-github-bot committed May 22, 2017
1 parent 8874016 commit 94ca83a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
29 changes: 18 additions & 11 deletions src/commands/findRefsCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,23 @@ let main option_values root json pretty strip_root path args () =
ServerProt.cmd_to_channel oc
(ServerProt.FIND_REFS (file, line, column));
(* command result will be a position structure with full file path *)
let locs: Loc.t list = Timeout.input_value ic in
(* format output *)
print_endline @@
if json || pretty
then Hh_json.(json_to_string ~pretty @@
JSON_Array (List.map (Reason.json_of_loc ~strip_root) locs)
)
else String.concat "\n" @@
if option_values.from = "vim" || option_values.from = "emacs"
then List.map (Errors.Vim_emacs_output.string_of_loc ~strip_root) locs
else List.map (range_string_of_loc ~strip_root) locs
let response: ServerProt.find_refs_response = Timeout.input_value ic in
match response with
| Ok locs ->
(* format output *)
print_endline @@
if json || pretty
then Hh_json.(json_to_string ~pretty @@
JSON_Array (List.map (Reason.json_of_loc ~strip_root) locs)
)
else String.concat "\n" @@
if option_values.from = "vim" || option_values.from = "emacs"
then List.map (Errors.Vim_emacs_output.string_of_loc ~strip_root) locs
else List.map (range_string_of_loc ~strip_root) locs
| Error exn_msg ->
Utils_js.prerr_endlinef
"Could not find refs for %s:%d:%d\n%s"
(ServerProt.file_input_get_filename file) line column exn_msg


let command = CommandSpec.command spec main
16 changes: 4 additions & 12 deletions src/server/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,9 @@ let collate_errors =
| _, Some cx, _, _ -> cx
| _ -> failwith "Couldn't parse file"
in
Some (FindRefs_js.result cx state)
Ok (FindRefs_js.result cx state)
with exn ->
Hh_logger.warn
"Could not find refs for %s:%d:%d\n%s"
filename line col
(Printexc.to_string exn);
None
Error (Printexc.to_string exn)
in
FindRefs_js.unset_hooks ();
result
Expand Down Expand Up @@ -591,10 +587,6 @@ let collate_errors =
Marshal.to_channel oc msg [];
flush oc
in
let marshal_option = function
| Some msg -> marshal msg
| None -> ()
in
let options = genv.ServerEnv.options in
let { ServerProt.client_logging_context; command; } = msg in
begin match command with
Expand All @@ -619,8 +611,8 @@ let collate_errors =
(find_module ~options (moduleref, filename): filename option)
|> marshal
| ServerProt.FIND_REFS (fn, line, char) ->
(find_refs ~options (fn, line, char): Loc.t list option)
|> marshal_option
(find_refs ~options (fn, line, char): ServerProt.find_refs_response)
|> marshal
| ServerProt.FORCE_RECHECK (files) ->
Marshal.to_channel oc () [];
flush oc;
Expand Down
1 change: 1 addition & 0 deletions src/server/serverProt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type dump_types_response = (
(Loc.t * string * string * string option * Reason.t list) list,
Loc.t * string
) result
type find_refs_response = (Loc.t list, string) result
type get_def_response = (Loc.t, string) result
type infer_type_response = (
Loc.t * string option * string option * Reason.t list,
Expand Down

0 comments on commit 94ca83a

Please sign in to comment.