Skip to content
Snippets Groups Projects
Commit d410b6f5 authored by Loïc Correnson's avatar Loïc Correnson Committed by Virgile Prevosto
Browse files

[mdr] more verbose & robustified channel closing

parent bd865df3
No related branches found
No related tags found
No related merge requests found
...@@ -621,12 +621,10 @@ let gen_report ~draft:is_draft () = ...@@ -621,12 +621,10 @@ let gen_report ~draft:is_draft () =
:: elements :: elements
in in
let doc = Markdown.pandoc ~title ~authors elements in let doc = Markdown.pandoc ~title ~authors elements in
let file = Mdr_params.Output.get() in
try try
let out = open_out (Mdr_params.Output.get()) in Command.print_file file (fun fmt -> Markdown.pp_pandoc fmt doc) ;
let fmt = Format.formatter_of_out_channel out in Mdr_params.result "Report %s generated" file
Markdown.pp_pandoc fmt doc;
close_out out
with Sys_error s -> with Sys_error s ->
Mdr_params.warning Mdr_params.warning
"Unable to open %s for writing (%s). No report will be generated" "Unable to open %s for writing (%s). No report generated" file s
(Mdr_params.Output.get()) s
...@@ -182,14 +182,14 @@ let gen_run remarks = ...@@ -182,14 +182,14 @@ let gen_run remarks =
let generate () = let generate () =
let remarks = get_remarks () in let remarks = get_remarks () in
let runs = [ gen_run remarks ] in let runs = [ gen_run remarks ] in
let json = Schema.create ~runs () in let json = Schema.create ~runs () |> Schema.to_yojson in
let out = Mdr_params.Output.get () in let file = Mdr_params.Output.get () in
let chan = if file = "" then
if out = "" then stdout Log.print_on_output (fun fmt -> Yojson.Safe.pretty_print fmt json)
else begin else
try open_out out try
with Sys_error s -> Command.write_file file
Mdr_params.abort "Unable to open output file %s: %s" out s (fun out -> Yojson.Safe.pretty_to_channel ~std:true out json) ;
end Mdr_params.result "Report %s generated" file
in with Sys_error s ->
Yojson.Safe.to_channel chan (Schema.to_yojson json) Mdr_params.abort "Unable to generate %s (%s)" file s
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment