From b2f153396b83b497d6aa5edafe5b88ad54b2d237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reynir=20Bj=C3=B6rnsson?= Date: Wed, 15 Jan 2025 13:43:18 +0100 Subject: [PATCH] console_of_string: be a bit more robust If a line somehow has an unexpected shape we log a warning and omit it. --- bin/builder_db_app.ml | 16 +++++++--------- lib/model.ml | 16 +++++++--------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/bin/builder_db_app.ml b/bin/builder_db_app.ml index e6f4283..d11e4d0 100644 --- a/bin/builder_db_app.ml +++ b/bin/builder_db_app.ml @@ -761,22 +761,20 @@ end (* NOTE: this function is duplicatedi in lib/model.ml *) let console_of_string data = - (* remove last empty line *) - let data = - if String.ends_with ~suffix:"\n" data then - String.sub data 0 (String.length data - 2) - else data - in let lines = String.split_on_char '\n' data in - List.map (fun line -> + List.filter_map (fun line -> match String.index line ':' with + | 0 -> Logs.warn (fun m -> m "console line starting with colon %S" line); None | i -> (* the timestamp is of the form "%fs", e.g. 0.867s; so chop off the 's' *) let delta = float_of_string (String.sub line 0 (i - 1)) in let delta = Int64.to_int (Duration.of_f delta) in let line = String.sub line i (String.length line - i) in - delta, line - | exception Not_found -> assert false) + Some (delta, line) + | exception Not_found -> + if line <> "" then + Logs.warn (fun m -> m "Unexpected console line %S" line); + None) lines let extract_full () datadir dest uuid = diff --git a/lib/model.ml b/lib/model.ml index b911e89..12a121e 100644 --- a/lib/model.ml +++ b/lib/model.ml @@ -526,22 +526,20 @@ let add_build (* NOTE: this function is duplicatedi in bin/builder_db_app.ml *) let console_of_string data = - (* remove last empty line *) - let data = - if String.ends_with ~suffix:"\n" data then - String.sub data 0 (String.length data - 2) - else data - in let lines = String.split_on_char '\n' data in - List.map (fun line -> + List.filter_map (fun line -> match String.index line ':' with + | 0 -> Log.warn (fun m -> m "console line starting with colon %S" line); None | i -> (* the timestamp is of the form "%fs", e.g. 0.867s; so chop off the 's' *) let delta = float_of_string (String.sub line 0 (i - 1)) in let delta = Int64.to_int (Duration.of_f delta) in let line = String.sub line i (String.length line - i) in - delta, line - | exception Not_found -> assert false) + Some (delta, line) + | exception Not_found -> + if line <> "" then + Log.warn (fun m -> m "Unexpected console line %S" line); + None) lines let exec_of_build datadir uuid (module Db : CONN) =