Skip to content

Commit 8976d09

Browse files
justin808claude
andcommitted
Simplify help message system - use hardcoded message
Remove dynamic extraction from README.md and use a consistent hardcoded help message throughout the codebase. The markdown-to-terminal conversion proved too fragile for reliable use. - Remove extract_troubleshooting_section and related helper methods - Update all error classes to use Utils.default_troubleshooting_section - Remove documentation comment about marker usage from README - Keep the well-formatted hardcoded support message with URLs This provides a more reliable and maintainable approach to displaying help information in error messages. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent e7a3b6a commit 8976d09

File tree

5 files changed

+8
-46
lines changed

5 files changed

+8
-46
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ _Requires creating a free account._
141141
- A JavaScript package manager (npm, yarn, pnpm, or bun)
142142

143143
<!-- TROUBLESHOOTING_LINKS_START -->
144-
<!-- NOTE: Content between TROUBLESHOOTING_LINKS markers is dynamically extracted and displayed in error messages -->
145144
# 🆘 Get Help & Support
146145

147146
**Need immediate help?** Here are your options, ordered by response time:

lib/react_on_rails/json_parse_error.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class JsonParseError < ::ReactOnRails::Error
77
def initialize(parse_error:, json:)
88
@json = json
99
@original_error = parse_error
10-
message = "#{parse_error.message}\n\n#{Utils.extract_troubleshooting_section}"
10+
message = "#{parse_error.message}\n\n#{Utils.default_troubleshooting_section}"
1111
super(message)
1212
end
1313

lib/react_on_rails/prerender_error.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def calc_message(component_name, console_messages, err, js_code, props)
8585
end
8686

8787
# Add help and support information
88-
message << "\n#{Utils.extract_troubleshooting_section}\n"
88+
message << "\n#{Utils.default_troubleshooting_section}\n"
8989

9090
[backtrace, message]
9191
end

lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def exec_server_render_js(js_code, render_options, js_evaluator = nil)
7777
if err.message.include?("ReferenceError: self is not defined")
7878
msg << "\nError indicates that you may have code-splitting incorrectly enabled.\n"
7979
end
80-
msg << "\n#{Utils.extract_troubleshooting_section}\n"
80+
msg << "\n#{Utils.default_troubleshooting_section}\n"
8181
raise ReactOnRails::Error, msg, err.backtrace
8282
end
8383

@@ -123,7 +123,7 @@ def read_bundle_js_code
123123
rescue StandardError => e
124124
msg = "You specified server rendering JS file: #{server_js_file}, but it cannot be " \
125125
"read. You may set the server_bundle_js_file in your configuration to be \"\" to " \
126-
"avoid this warning.\nError is: #{e}\n\n#{Utils.extract_troubleshooting_section}"
126+
"avoid this warning.\nError is: #{e}\n\n#{Utils.default_troubleshooting_section}"
127127
raise ReactOnRails::Error, msg
128128
end
129129

@@ -151,7 +151,7 @@ def create_js_context
151151
"See file #{file_name} to " \
152152
"correlate line numbers of error. Error is\n\n#{e.message}" \
153153
"\n\n#{e.backtrace.join("\n")}" \
154-
"\n\n#{Utils.extract_troubleshooting_section}"
154+
"\n\n#{Utils.default_troubleshooting_section}"
155155
Rails.logger.error(msg)
156156
trace_js_code_used("Error when compiling JavaScript code for the context.", base_js_code,
157157
file_name, force: true)
@@ -229,7 +229,7 @@ def file_url_to_string(url)
229229
encoding_type = match[:encoding]
230230
response.body.force_encoding(encoding_type)
231231
rescue StandardError => e
232-
msg = "file_url_to_string #{url} failed\nError is: #{e}\n\n#{Utils.extract_troubleshooting_section}"
232+
msg = "file_url_to_string #{url} failed\nError is: #{e}\n\n#{Utils.default_troubleshooting_section}"
233233
raise ReactOnRails::Error, msg
234234
end
235235

lib/react_on_rails/utils.rb

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def self.invoke_and_exit_if_failed(cmd, failure_message)
5858

5959
puts wrap_message(msg)
6060
puts ""
61-
puts extract_troubleshooting_section
61+
puts default_troubleshooting_section
6262

6363
# Rspec catches exit without! in the exit callbacks
6464
exit!(1)
@@ -281,40 +281,7 @@ def self.prepend_to_file_if_text_not_present(file:, text_to_prepend:, regex:)
281281
puts "Prepended\n#{text_to_prepend}to #{file}."
282282
end
283283

284-
# Extract troubleshooting section from README.md for error messages
285-
def self.extract_troubleshooting_section
286-
readme_path = File.join(gem_root, "README.md")
287-
return default_troubleshooting_section unless File.exist?(readme_path)
288-
289-
readme_content = File.read(readme_path)
290-
291-
# Extract content between the markers
292-
start_marker = "<!-- TROUBLESHOOTING_LINKS_START -->"
293-
end_marker = "<!-- TROUBLESHOOTING_LINKS_END -->"
294-
295-
if readme_content.include?(start_marker) && readme_content.include?(end_marker)
296-
start_pos = readme_content.index(start_marker) + start_marker.length
297-
end_pos = readme_content.index(end_marker)
298-
299-
extracted = readme_content[start_pos...end_pos].strip
300-
# Convert markdown to terminal-friendly text
301-
convert_markdown_to_terminal(extracted)
302-
else
303-
default_troubleshooting_section
304-
end
305-
rescue StandardError
306-
default_troubleshooting_section
307-
end
308-
309-
private_class_method def self.convert_markdown_to_terminal(markdown_text)
310-
markdown_text
311-
.gsub(/^#+\s+(.+)$/, "\n📞 \\1") # Convert H1-H6 headers
312-
.gsub(/\*\*(.+?)\*\*/, "\\1") # Remove bold markdown
313-
.gsub(/\[([^\]]+)\]\(([^)]+)\)/, "\\1: \\2") # Convert links to "text: url"
314-
.gsub(/^-\s+/, " • ") # Convert bullets
315-
end
316-
317-
private_class_method def self.default_troubleshooting_section
284+
def self.default_troubleshooting_section
318285
<<~DEFAULT
319286
📞 Get Help & Support:
320287
• 🚀 Professional Support: react_on_rails@shakacode.com (fastest resolution)
@@ -323,9 +290,5 @@ def self.extract_troubleshooting_section
323290
• 📖 Discussions: https://github.com/shakacode/react_on_rails/discussions
324291
DEFAULT
325292
end
326-
327-
private_class_method def self.gem_root
328-
File.expand_path("../..", __dir__)
329-
end
330293
end
331294
end

0 commit comments

Comments
 (0)