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)
This commit is contained in:
Dmitry Bushev 2023-06-30 20:06:19 +01:00 committed by GitHub
parent c866aa7fb5
commit bb862141e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -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

View File

@ -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