Skip to content

Commit

Permalink
Small cleanup for new error format
Browse files Browse the repository at this point in the history
Reviewed By: @jeffmo

Differential Revision: D2517143

fb-gh-sync-id: c9a282b3920c5bde2de957ae4d6f00adce7eac64
  • Loading branch information
gabelevi authored and facebook-github-bot-4 committed Oct 7, 2015
1 parent a72500c commit 257fbad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
30 changes: 14 additions & 16 deletions src/common/errors_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -214,25 +214,29 @@ let print_file_at_location ~root stdin_file main_file loc s = Loc.(
(Some stdin_filename) = filename, Some (stdin_filename, content)
| _ -> false, stdin_file in

let see_another_file filename =
if filename = main_file
then [(default_style "")]
else [
comment_style ". See: ";
comment_file_style (Printf.sprintf "%s:%d" (relative_path filename) l0)
] in

match using_stdin, filename with
| _, None ->
[
comment_style (Printf.sprintf "%s" s);
comment_style s;
default_style "\n";
]
| false, Some fn when not (Sys.file_exists fn) ->
let original_filename = match loc.source with
| Some Loc.LibFile filename
| Some Loc.SourceFile filename -> filename
| Some Loc.Builtins
| None -> failwith "Should only have lib and source files at this point"
in
[
comment_style (Printf.sprintf "%s" s);
comment_style ". See: ";
comment_file_style (Printf.sprintf "%s:%d" (relative_path original_filename) l0);
default_style "\n";
]
| None -> failwith "Should only have lib and source files at this point" in
[comment_style s] @
(see_another_file original_filename) @
[default_style "\n"];
| _, Some filename ->
let line_number_text = Printf.sprintf "%3d: " l0 in
let code_line = read_line_in_file (l0 - 1) filename stdin_file in
Expand All @@ -247,16 +251,10 @@ let print_file_at_location ~root stdin_file main_file loc s = Loc.(
else 1
in
let underline = String.make underline_size '^' in
let see_another_file = if filename == main_file then [(default_style "")] else
[
comment_style ". See: ";
comment_file_style (Printf.sprintf "%s:%d" (relative_path filename) l0)
]
in
line_number_style line_number_text ::
highlighted_line @
[comment_style (Printf.sprintf "\n%s%s %s" padding underline s)] @
see_another_file @
(see_another_file filename) @
[default_style "\n"]
)

Expand Down
1 change: 0 additions & 1 deletion src/common/reason_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ let strip_root_from_loc root loc = Loc.(
| None -> None
| Some Builtins -> Some Builtins
| Some LibFile file ->
Utils.prerr_endlinef "%s" file;
let root_str = spf "%s%s" (Path.to_string root) Filename.dir_sep in
if Str.string_match (Str.regexp_string root_str) file 0
then Some (LibFile (spf "[LIB] %s" (Files_js.relative_path root_str file)))
Expand Down

0 comments on commit 257fbad

Please sign in to comment.