Skip to content

Commit

Permalink
Truncate long error messages (#7180)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
4e6 authored Jun 30, 2023
1 parent c866aa7 commit bb86214
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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


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

0 comments on commit bb86214

Please sign in to comment.