Skip to content

Commit 02e51b1

Browse files
committed
Ignore warnings from gem_prelude
With the latest `wasm-wasi`, the following warnings are shown on TryRuby. ``` `RubyGems' were not loaded. `error_highlight' was not loaded. `did_you_mean' was not loaded. `syntax_suggest' was not loaded. ``` This warnings come from `gem_prelude.rb`. https://github.com/ruby/ruby/blob/master/gem_prelude.rb I assume this this is because the current usage of `ruby.wasm` on TryRuby don't consider RubyGems and fails to load it. We should change the structure of how to use `ruby.wasm` for fixing this. But, this is just warnings and there are no other issues. And, it seems that this warnings would not be shown in Ruby 3.5 ruby/ruby@4e303fd ruby/ruby@e9dadf1 So I fixed to just silence those warnings.
1 parent c6b7e13 commit 02e51b1

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

app/try_ruby.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ class TryRuby
1717

1818
DEFAULT_RUBY_ENGINE = "cruby-3.4.1"
1919

20+
GEM_PRELUDE_WARNINGS = [
21+
"`RubyGems' were not loaded.",
22+
"`error_highlight' was not loaded.",
23+
"`did_you_mean' was not loaded.",
24+
"`syntax_suggest' was not loaded."
25+
].freeze
26+
2027
def self.start
2128
instance
2229
end
@@ -455,13 +462,24 @@ def log_error(err)
455462
end
456463

457464
def print_to_output(str, term = "\n")
465+
return if warnings_from_gem_prelude?(str)
458466
@output_buffer << str.to_s + term
459467
@output.value = @output_buffer.join
460468
end
461469

462470
def output=(text)
463471
@output.value = text
464472
end
473+
474+
# TODO: This would be needless if only supports Ruby >= 3.5.
475+
def warnings_from_gem_prelude?(str)
476+
return false if str.nil? || str.empty?
477+
478+
trimmed_str = str.strip
479+
GEM_PRELUDE_WARNINGS.include?(trimmed_str)
480+
end
481+
482+
private
465483
end
466484

467485
$window.on("dom:load") { TryRuby.start }

0 commit comments

Comments
 (0)