Skip to content

Commit

Permalink
Merge pull request #1574 from sinsoku/avoid-syntax-error
Browse files Browse the repository at this point in the history
Avoid an error when parsing files including SyntaxError
  • Loading branch information
soutaro committed Oct 30, 2023
2 parents e05966b + 526a459 commit fea32c3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/rbs/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,12 @@ def run_prototype_file(format, args)
output_path = (output_dir + relative_path).sub_ext(".rbs")

parser = new_parser[]
parser.parse file_path.read()
begin
parser.parse file_path.read()
rescue SyntaxError
stdout.puts " ⚠️ Unable to parse due to SyntaxError: `#{file_path}`"
next
end

if output_path.file?
if force
Expand Down
26 changes: 26 additions & 0 deletions test/rbs/cli_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,32 @@ module A
end
end

def test_prototype_batch_syntax_error
Dir.mktmpdir do |dir|
dir = Pathname(dir)

(dir + "lib").mkdir
(dir + "lib/a.rb").write(<<-RUBY)
class A < <%= @superclass %>
end
RUBY

Dir.chdir(dir) do
with_cli do |cli|
cli.run(%w(prototype rb --out_dir=sig lib))

assert_equal <<-EOM, cli.stdout.string
Processing `lib`...
Generating RBS for `lib/a.rb`...
⚠️ Unable to parse due to SyntaxError: `lib/a.rb`
EOM
end
end

refute_predicate dir + "sig", :directory?
end
end

def test_prototype__runtime__todo
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
Expand Down

0 comments on commit fea32c3

Please sign in to comment.