From bb862141e536c87d26bb4fdbb117c32574efc80c Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Fri, 30 Jun 2023 20:06:19 +0100 Subject: [PATCH] Truncate long error messages (#7180) close #6958 # Important Notes On the screenshot, the `max_length` is set to 10 to illustrate the new behavior. ![2023-06-30-205255_758x483_scrot](https://github.com/enso-org/enso/assets/357683/0b593b12-4469-49fd-a2e5-216ce54eb264) --- .../lib/Standard/Visualization/0.0.0-dev/src/Helpers.enso | 6 ++++++ .../Standard/Visualization/0.0.0-dev/src/Preprocessor.enso | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/distribution/lib/Standard/Visualization/0.0.0-dev/src/Helpers.enso b/distribution/lib/Standard/Visualization/0.0.0-dev/src/Helpers.enso index e1badf4905c..98bd190509a 100644 --- a/distribution/lib/Standard/Visualization/0.0.0-dev/src/Helpers.enso +++ b/distribution/lib/Standard/Visualization/0.0.0-dev/src/Helpers.enso @@ -284,3 +284,9 @@ Row.to_default_visualization_data self = Table.to_lazy_visualization_data : Vector Integer -> Vector Integer -> Vector Integer -> Integer -> Text Table.to_lazy_visualization_data self table_cell_position text_window_position text_window_size chunk_size = Table_Visualization.get_lazy_visualization_data self table_cell_position text_window_position text_window_size chunk_size + +## PRIVATE + Truncate message to the provided max length. +truncate : Text -> Integer -> Text -> Text +truncate message max_length=256 suffix='...' = + if message.length > max_length then message.take max_length-suffix.length + suffix else message diff --git a/distribution/lib/Standard/Visualization/0.0.0-dev/src/Preprocessor.enso b/distribution/lib/Standard/Visualization/0.0.0-dev/src/Preprocessor.enso index 4e13d098336..4a52804b055 100644 --- a/distribution/lib/Standard/Visualization/0.0.0-dev/src/Preprocessor.enso +++ b/distribution/lib/Standard/Visualization/0.0.0-dev/src/Preprocessor.enso @@ -6,7 +6,7 @@ import project.Helpers default_preprocessor x = result = x.to_default_visualization_data case result.is_error of - True -> x.to_display_text . to_json + True -> Helpers.truncate x.to_display_text . to_json False -> result @@ -23,7 +23,8 @@ error_preprocessor x = result = x.map_error err-> message = err.to_display_text stack_trace = x.get_stack_trace_text.if_nothing "" . split '\n' - full_message = message + if stack_trace.length > 1 then " (" + stack_trace.at 1 . trim +")" else "" + truncated_message = Helpers.truncate message + full_message = truncated_message + if stack_trace.length > 1 then " (" + stack_trace.at 1 . trim +")" else "" JS_Object.from_pairs [['kind', 'Dataflow'], ['message', full_message]] . to_json if result.is_error then result.catch else ok