Skip to content

Commit b6bcc2e

Browse files
committed
Output the file path when an error occurs during analysis
Add error handling to output the path of the file being analyzed when an exception occurs, making it easier to identify which file caused the error.
1 parent 24cf28e commit b6bcc2e

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

lib/typeprof/core/service.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,9 @@ def batch(files, output)
511511
output.puts "# failed to analyze: #{ file }"
512512
false
513513
end
514+
rescue => e
515+
output.puts "# error: #{ file }"
516+
raise e
514517
end
515518
if @options[:display_indicator]
516519
$stderr << "\r\e[K"

test/core/service_test.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require_relative "../helper"
2+
require "stringio"
3+
require "tempfile"
4+
5+
module TypeProf::Core
6+
class ServiceTest < Test::Unit::TestCase
7+
def test_runtime_error
8+
options = {}
9+
service = TypeProf::Core::Service.new(options)
10+
11+
# Mocking an error while analyzing a file
12+
service.extend(Module.new do
13+
def update_rb_file(...)
14+
raise
15+
end
16+
end)
17+
18+
Tempfile.create(["", ".rb"]) do |f|
19+
output = StringIO.new(+"")
20+
assert_raises(RuntimeError) { service.batch([f.path], output) }
21+
assert_equal("# error: #{f.path}\n", output.string)
22+
end
23+
end
24+
end
25+
end

0 commit comments

Comments
 (0)