Exception: ReactOnRails::PrerenderError
- Defined in:
- lib/react_on_rails/prerender_error.rb,
sig/react_on_rails/prerender_error.rbs
Constant Summary collapse
- REDACTED_VALUE =
"[REDACTED]"- SENSITIVE_CONTEXT_KEYS =
%w[props js_code json].freeze
Instance Attribute Summary collapse
-
#component_name ⇒ String?
readonly
TODO: Consider remove providing original
erras already have access toself.causehttp://blog.honeybadger.io/nested-errors-in-ruby-with-exception-cause/. -
#console_messages ⇒ String?
readonly
TODO: Consider remove providing original
erras already have access toself.causehttp://blog.honeybadger.io/nested-errors-in-ruby-with-exception-cause/. -
#err ⇒ StandardError?
readonly
TODO: Consider remove providing original
erras already have access toself.causehttp://blog.honeybadger.io/nested-errors-in-ruby-with-exception-cause/. -
#js_code ⇒ String?
readonly
TODO: Consider remove providing original
erras already have access toself.causehttp://blog.honeybadger.io/nested-errors-in-ruby-with-exception-cause/. -
#props ⇒ String?
readonly
TODO: Consider remove providing original
erras already have access toself.causehttp://blog.honeybadger.io/nested-errors-in-ruby-with-exception-cause/.
Instance Method Summary collapse
-
#build_troubleshooting_suggestions(component_name, err, console_messages) ⇒ String
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity.
-
#calc_message(component_name, console_messages, err, js_code, props) ⇒ [String?, String]
rubocop:disable Metrics/AbcSize.
-
#initialize(component_name: nil, err: nil, props: nil, js_code: nil, console_messages: nil) ⇒ PrerenderError
constructor
err might be nil if JS caught the error.
- #raven_context ⇒ Hash[Symbol, untyped]
- #to_error_context ⇒ Hash[Symbol, untyped]
- #to_honeybadger_context ⇒ Hash[Symbol, untyped]
Constructor Details
#initialize(component_name: nil, err: nil, props: nil, js_code: nil, console_messages: nil) ⇒ PrerenderError
err might be nil if JS caught the error
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/react_on_rails/prerender_error.rb', line 15 def initialize(component_name: nil, err: nil, props: nil, js_code: nil, console_messages: nil) @component_name = component_name @err = err @props = redacted_value(props) @js_code = redacted_value(js_code) @console_messages = backtrace, = (component_name, , err, js_code, props) super([, backtrace].compact.join("\n")) end |
Instance Attribute Details
#component_name ⇒ String? (readonly)
TODO: Consider remove providing original err as already have access to self.cause
http://blog.honeybadger.io/nested-errors-in-ruby-with-exception-cause/
12 13 14 |
# File 'lib/react_on_rails/prerender_error.rb', line 12 def component_name @component_name end |
#console_messages ⇒ String? (readonly)
TODO: Consider remove providing original err as already have access to self.cause
http://blog.honeybadger.io/nested-errors-in-ruby-with-exception-cause/
12 13 14 |
# File 'lib/react_on_rails/prerender_error.rb', line 12 def @console_messages end |
#err ⇒ StandardError? (readonly)
TODO: Consider remove providing original err as already have access to self.cause
http://blog.honeybadger.io/nested-errors-in-ruby-with-exception-cause/
12 13 14 |
# File 'lib/react_on_rails/prerender_error.rb', line 12 def err @err end |
#js_code ⇒ String? (readonly)
TODO: Consider remove providing original err as already have access to self.cause
http://blog.honeybadger.io/nested-errors-in-ruby-with-exception-cause/
12 13 14 |
# File 'lib/react_on_rails/prerender_error.rb', line 12 def js_code @js_code end |
#props ⇒ String? (readonly)
TODO: Consider remove providing original err as already have access to self.cause
http://blog.honeybadger.io/nested-errors-in-ruby-with-exception-cause/
12 13 14 |
# File 'lib/react_on_rails/prerender_error.rb', line 12 def props @props end |
Instance Method Details
#build_troubleshooting_suggestions(component_name, err, console_messages) ⇒ String
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/react_on_rails/prerender_error.rb', line 137 def build_troubleshooting_suggestions(component_name, err, ) suggestions = [] # Check for common error patterns if err&.&.include?("window is not defined") || &.include?("window is not defined") suggestions << <<~SUGGESTION 1. Browser API used on server - wrap with client-side check: #{Rainbow("if (typeof window !== 'undefined') { ... }").cyan} SUGGESTION end if err&.&.include?("document is not defined") || &.include?("document is not defined") suggestions << <<~SUGGESTION 1. DOM API used on server - use React refs or useEffect: #{Rainbow('useEffect(() => { /* DOM operations here */ }, [])').cyan} SUGGESTION end if err&.&.include?("Cannot read") || err&.&.include?("undefined") suggestions << <<~SUGGESTION 1. Check for null/undefined values in props 2. Add default props or use optional chaining: #{Rainbow("props.data?.value || 'default'").cyan} SUGGESTION end if err&.&.include?("Hydration") || &.include?("Hydration") suggestions << <<~SUGGESTION 1. Server and client render mismatch - ensure consistent: - Random values (use seed from props) - Date/time values (pass from server) - User agent checks (avoid or use props) SUGGESTION end # Generic suggestions suggestions << <<~SUGGESTION • Temporarily disable SSR to isolate the issue: #{Rainbow('prerender: false').cyan} in your view helper • Check server logs for detailed errors: #{Rainbow('tail -f log/development.log').cyan} • Verify component registration: #{Rainbow("ReactOnRails.register({ #{component_name}: #{component_name} })").cyan} • Ensure server bundle is up to date: #{Rainbow('bin/shakapacker').cyan} or #{Rainbow('yarn run build:server').cyan} SUGGESTION suggestions.join("\n") # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity end |
#calc_message(component_name, console_messages, err, js_code, props) ⇒ [String?, String]
rubocop:disable Metrics/AbcSize
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/react_on_rails/prerender_error.rb', line 77 def (component_name, , err, js_code, props) header = Rainbow("❌ React on Rails Server Rendering Error").red.bright = +"#{header}\n\n" << Rainbow("Component: #{component_name}").yellow << "\n\n" if err << Rainbow("Error Details:").red.bright << "\n" << <<~MSG #{safe_error_details(err)} MSG backtrace = formatted_backtrace(err) else backtrace = nil end # Add props information << Rainbow("Props:").blue.bright << "\n" << "#{redacted_value(props)}\n\n" # Add code snippet << Rainbow("JavaScript Code:").blue.bright << "\n" << "#{redacted_value(js_code)}\n\n" if && .strip.present? << Rainbow("Console Output:").magenta.bright << "\n" << "#{}\n\n" end # Add actionable suggestions << Rainbow("💡 Troubleshooting Steps:").yellow.bright << "\n" << build_troubleshooting_suggestions(component_name, err, ) # Add help and support information << "\n#{Utils.default_troubleshooting_section}\n" [backtrace, ] # rubocop:enable Metrics/AbcSize end |
#raven_context ⇒ Hash[Symbol, untyped]
32 33 34 |
# File 'lib/react_on_rails/prerender_error.rb', line 32 def raven_context to_error_context end |
#to_error_context ⇒ Hash[Symbol, untyped]
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/react_on_rails/prerender_error.rb', line 36 def to_error_context result = { component_name:, err: error_context_value(err), props:, js_code:, console_messages: } if err.respond_to?(:to_error_context) nested_context = err.to_error_context.reject { |key, _value| sensitive_nested_context_key?(key) } result.merge!(nested_context) end result end |
#to_honeybadger_context ⇒ Hash[Symbol, untyped]
28 29 30 |
# File 'lib/react_on_rails/prerender_error.rb', line 28 def to_honeybadger_context to_error_context end |