Skip to content

Commit f72a767

Browse files
committed
Fix obscure errors by introducing FULL_TEXT_ERRORS
1 parent 90033e7 commit f72a767

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

lib/react_on_rails/prerender_error.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
require "rainbow"
4+
35
# rubocop:disable: Layout/IndentHeredoc
46
module ReactOnRails
57
class PrerenderError < ::ReactOnRails::Error
@@ -51,11 +53,17 @@ def calc_message(component_name, console_messages, err, js_code, props)
5153
message << <<~MSG
5254
Encountered error:
5355
54-
#{err}
56+
#{err.inspect}
5557
5658
MSG
5759

58-
backtrace = err.backtrace.first(15).join("\n")
60+
backtrace = if ENV["FULL_TEXT_ERRORS"] == "true"
61+
err.backtrace.join("\n")
62+
else
63+
"#{err.backtrace.first(15).join("\n")}\n" +
64+
Rainbow("The rest of the backtrace is hidden. " \
65+
"To see the full backtrace, set FULL_TEXT_ERRORS=true.").red
66+
end
5967
else
6068
backtrace = nil
6169
end

lib/react_on_rails/utils.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
module ReactOnRails
1010
module Utils
11-
TRUNCATION_FILLER = "\n... TRUNCATED ...\n"
11+
TRUNCATION_FILLER = "\n... TRUNCATED #{
12+
Rainbow('To see the full output, set FULL_TEXT_ERRORS=true.').red
13+
} ...\n".freeze
1214

1315
# https://forum.shakacode.com/t/yak-of-the-week-ruby-2-4-pathname-empty-changed-to-look-at-file-size/901
1416
# return object if truthy, else return nil
@@ -186,6 +188,7 @@ def self.react_on_rails_pro_version
186188
def self.smart_trim(str, max_length = 1000)
187189
# From https://stackoverflow.com/a/831583/1009332
188190
str = str.to_s
191+
return str if ENV["FULL_TEXT_ERRORS"] == "true"
189192
return str unless str.present? && max_length >= 1
190193
return str if str.length <= max_length
191194

0 commit comments

Comments
 (0)