Skip to content

Commit

Permalink
Allow debugging errors in server gen js
Browse files Browse the repository at this point in the history
This change prints a useful message and outputs the file with the issue.
  • Loading branch information
justin808 committed Jan 31, 2016
1 parent d1b44d6 commit ea16151
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions lib/react_on_rails/server_rendering_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ def self.server_render_js_with_console_logging(js_code)
class << self
private

def trace_messsage(js_code)
def trace_messsage(js_code, file_name = "tmp/server-generated.js")
return unless ENV["TRACE_REACT_ON_RAILS"].present?
# Set to anything to print generated code.
puts "Z" * 80
puts "react_renderer.rb: 92"
puts "wrote file tmp/server-generated.js"
File.write("tmp/server-generated.js", js_code)
puts "wrote file #{file_name}"
File.write(file_name, js_code)
puts "Z" * 80
end

Expand All @@ -77,7 +77,19 @@ def create_js_context
#{console_polyfill}
#{bundle_js_code};
JS
ExecJS.compile(base_js_code)
begin
ExecJS.compile(base_js_code)
rescue => e
file_name = "tmp/base_js_code.js"
msg = "ERROR when compiling base_js_code! See #{file_name} to "\
"ERROR when compiling base_js_code! See #{file_name} to "\
"correlate line numbers of error. Error is\n\n#{e.message}"\
"\n\n#{e.backtrace.join("\n")}"
puts msg
Rails.logger.error(msg)
trace_messsage(base_js_code, file_name)
raise e
end
else
if server_js_file.present?
msg = "You specified server rendering JS file: #{server_js_file}, but it cannot be "\
Expand Down

0 comments on commit ea16151

Please sign in to comment.