From 1f3ce79023d902d0145da38e878d991a6ba29236 Mon Sep 17 00:00:00 2001 From: Son Ho Date: Thu, 4 Apr 2024 15:47:54 +0200 Subject: Update the way errors are reported --- compiler/Errors.ml | 6 ------ compiler/Main.ml | 11 +++++++---- 2 files changed, 7 insertions(+), 10 deletions(-) (limited to 'compiler') diff --git a/compiler/Errors.ml b/compiler/Errors.ml index 7dfe659a..30887593 100644 --- a/compiler/Errors.ml +++ b/compiler/Errors.ml @@ -20,12 +20,6 @@ let format_error_message_with_file_line (file : string) (line : int) "In file " ^ file ^ ", line " ^ string_of_int line ^ ":\n" ^ format_error_message meta msg -let error_list_to_string (error_list : (Meta.meta option * string) list) : - string = - List.fold_left - (fun errors (meta, msg) -> errors ^ "\n" ^ format_error_message meta msg) - "" error_list - exception CFailure of (Meta.meta option * string) let error_list : (Meta.meta option * string) list ref = ref [] diff --git a/compiler/Main.ml b/compiler/Main.ml index 9e72a21b..416f3a07 100644 --- a/compiler/Main.ml +++ b/compiler/Main.ml @@ -278,10 +278,13 @@ let () = (* In theory it shouldn't happen, but there may be uncaught errors - note that we let the [Failure] exceptions go through (they are send if we use the option [-abort-on-error] *) - if not (List.is_empty !Errors.error_list) then ( - let errors = Errors.error_list_to_string !Errors.error_list in - log#serror errors; - exit 1)); + ()); + + if !Errors.error_list <> [] then ( + List.iter + (fun (meta, msg) -> log#serror (Errors.format_error_message meta msg)) + !Errors.error_list; + exit 1); (* Print total elapsed time *) log#linfo -- cgit v1.2.3