Skip to content

Commit 8482da5

Browse files
committed
Raise an AppMap exception instead of MethodSource::SourceNotFoundError
1 parent 2d8ef79 commit 8482da5

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

lib/appmap/trace.rb

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ def source_location
4646
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
4747
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
4848
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
49+
50+
class SourceNotFoundError < StandardError; end
51+
4952
def appmap_extract_last_comment(lines)
5053
buffer = []
5154

@@ -72,11 +75,11 @@ def appmap_lines_for(file_name, name=nil)
7275
@lines_for_file ||= {}
7376
@lines_for_file[file_name] ||= File.readlines(file_name)
7477
rescue Errno::ENOENT => e
75-
raise MethodSource::SourceNotFoundError, "Could not load source for #{name}: #{e.message}"
78+
raise AppMap::Trace::RubyMethod::SourceNotFoundError, "Could not load source for #{name}: #{e.message}"
7679
end
7780

7881
def appmap_comment_helper(source_location, name=nil)
79-
raise MethodSource::SourceNotFoundError, "Could not locate source for #{name}!" unless source_location
82+
raise AppMap::Trace::RubyMethod::SourceNotFoundError, "Could not locate source for #{name}!" unless source_location
8083
file, line = *source_location
8184

8285
appmap_comment_describing(appmap_lines_for(file), line)
@@ -86,18 +89,21 @@ def comment
8689
# use AppMap's optimization in appmap_extract_last_comment to
8790
# extract comments...
8891
appmap_comment_helper(source_location, defined?(name) ? name : inspect)
89-
9092
# ... instead of use MethodSource which hasn't merged
9193
# https://github.com/banister/method_source/pull/78. When/if
9294
# this pr gets merged, AppMap's optimization can be removed
93-
# and the following code can be uncommented:
94-
95-
# @method.comment
96-
rescue MethodSource::SourceNotFoundError, Errno::EINVAL
95+
# and the previous implementation of "def comment" can be uncommented:
96+
rescue AppMap::Trace::RubyMethod::SourceNotFoundError, Errno::EINVAL
9797
nil
9898
end
9999
# =======================================================================
100100

101+
# def comment
102+
# @method.comment
103+
# rescue MethodSource::SourceNotFoundError, Errno::EINVAL
104+
# nil
105+
# end
106+
101107
def package
102108
@package.name
103109
end

0 commit comments

Comments
 (0)