Skip to content

Commit 9a152d8

Browse files
committed
fix: Catch an uncaught EINVAL on Windows when attempting to parse source code
The `method_source` gem will happily take a source path such as `<internal:pack>:243` and attempt to open it as a file. In this case, Windows will raise an EINVAL error which is not caught by the gem and the error will propagate through the agent and fail a recording.
1 parent 61177cc commit 9a152d8

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/appmap/trace.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def source_location
2222

2323
def comment
2424
@method.comment
25-
rescue MethodSource::SourceNotFoundError
25+
rescue MethodSource::SourceNotFoundError, Errno::EINVAL
2626
nil
2727
end
2828

spec/ruby_method_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe AppMap::Trace::RubyMethod do
6+
# These tests are mostly targeted towards Windows. Make sure no operating system errors go unhandled.
7+
describe :comment do
8+
# These methods use native implementations, and their source code files are not regular file paths.
9+
let(:methods) { [''.method(:unpack1), Kernel.instance_method(:eval)] }
10+
11+
it 'properly handles invalid source file paths' do
12+
methods.each do |method|
13+
ruby_method = AppMap::Trace::RubyMethod.new(nil, nil, method, false)
14+
expect { ruby_method.comment }.not_to raise_error
15+
end
16+
end
17+
end
18+
end

0 commit comments

Comments
 (0)