Frame#file -> Frame#path

This commit is contained in:
Sijawusz Pur Rahnama 2020-12-28 18:57:38 +01:00
parent 1fe6177e0d
commit 6a5100dc61
2 changed files with 26 additions and 26 deletions

View file

@ -43,7 +43,7 @@ describe Backtracer::Backtrace::Frame do
frame.lineno.should be_nil frame.lineno.should be_nil
frame.column.should be_nil frame.column.should be_nil
frame.method.should eq(backtrace_line) frame.method.should eq(backtrace_line)
frame.file.should be_nil frame.path.should be_nil
frame.relative_path.should be_nil frame.relative_path.should be_nil
frame.under_src_path?.should be_false frame.under_src_path?.should be_false
frame.shard_name.should be_nil frame.shard_name.should be_nil
@ -60,7 +60,7 @@ describe Backtracer::Backtrace::Frame do
frame.lineno.should eq(72) frame.lineno.should eq(72)
frame.column.should be_nil frame.column.should be_nil
frame.method.should eq("~proc2Proc(Fiber, (IO::FileDescriptor | Nil))") frame.method.should eq("~proc2Proc(Fiber, (IO::FileDescriptor | Nil))")
frame.file.should eq("/usr/local/Cellar/crystal/0.27.2/src/fiber.cr") frame.path.should eq("/usr/local/Cellar/crystal/0.27.2/src/fiber.cr")
frame.relative_path.should be_nil frame.relative_path.should be_nil
frame.under_src_path?.should be_false frame.under_src_path?.should be_false
frame.shard_name.should be_nil frame.shard_name.should be_nil
@ -75,7 +75,7 @@ describe Backtracer::Backtrace::Frame do
frame.lineno.should eq(11) frame.lineno.should eq(11)
frame.column.should be_nil frame.column.should be_nil
frame.method.should eq("~procProc(HTTP::Server::Context, String)") frame.method.should eq("~procProc(HTTP::Server::Context, String)")
frame.file.should eq("lib/kemal/src/kemal/route.cr") frame.path.should eq("lib/kemal/src/kemal/route.cr")
frame.relative_path.should eq("lib/kemal/src/kemal/route.cr") frame.relative_path.should eq("lib/kemal/src/kemal/route.cr")
frame.under_src_path?.should be_false frame.under_src_path?.should be_false
frame.shard_name.should eq("kemal") frame.shard_name.should eq("kemal")
@ -91,7 +91,7 @@ describe Backtracer::Backtrace::Frame do
frame.lineno.should eq(1) frame.lineno.should eq(1)
frame.column.should eq(7) frame.column.should eq(7)
frame.method.should eq("foo_bar?") frame.method.should eq("foo_bar?")
frame.file.should eq(path) frame.path.should eq(path)
frame.relative_path.should be_nil frame.relative_path.should be_nil
frame.under_src_path?.should be_false frame.under_src_path?.should be_false
frame.shard_name.should be_nil frame.shard_name.should be_nil
@ -105,7 +105,7 @@ describe Backtracer::Backtrace::Frame do
frame.lineno.should eq(1) frame.lineno.should eq(1)
frame.column.should eq(7) frame.column.should eq(7)
frame.method.should eq("foo_bar?") frame.method.should eq("foo_bar?")
frame.file.should eq("#{__DIR__}/foo.cr") frame.path.should eq("#{__DIR__}/foo.cr")
frame.relative_path.should eq("spec/backtracer/backtrace/foo.cr") frame.relative_path.should eq("spec/backtracer/backtrace/foo.cr")
frame.under_src_path?.should be_true frame.under_src_path?.should be_true
frame.shard_name.should be_nil frame.shard_name.should be_nil
@ -120,7 +120,7 @@ describe Backtracer::Backtrace::Frame do
frame.lineno.should eq(1) frame.lineno.should eq(1)
frame.column.should eq(7) frame.column.should eq(7)
frame.method.should eq("foo_bar?") frame.method.should eq("foo_bar?")
frame.file.should eq(path) frame.path.should eq(path)
frame.relative_path.should eq(path) frame.relative_path.should eq(path)
frame.under_src_path?.should be_false frame.under_src_path?.should be_false
frame.shard_name.should be_nil frame.shard_name.should be_nil
@ -138,7 +138,7 @@ describe Backtracer::Backtrace::Frame do
frame.lineno.should eq(1) frame.lineno.should eq(1)
frame.column.should eq(7) frame.column.should eq(7)
frame.method.should eq("foo_bar?") frame.method.should eq("foo_bar?")
frame.file.should eq(path) frame.path.should eq(path)
frame.relative_path.should eq("src/foo.cr") frame.relative_path.should eq("src/foo.cr")
frame.under_src_path?.should be_true frame.under_src_path?.should be_true
frame.shard_name.should be_nil frame.shard_name.should be_nil
@ -153,7 +153,7 @@ describe Backtracer::Backtrace::Frame do
frame.lineno.should eq(1) frame.lineno.should eq(1)
frame.column.should eq(7) frame.column.should eq(7)
frame.method.should eq("foo_bar?") frame.method.should eq("foo_bar?")
frame.file.should eq(path) frame.path.should eq(path)
frame.relative_path.should eq(path) frame.relative_path.should eq(path)
frame.under_src_path?.should be_false frame.under_src_path?.should be_false
frame.shard_name.should be_nil frame.shard_name.should be_nil
@ -171,7 +171,7 @@ describe Backtracer::Backtrace::Frame do
frame.lineno.should eq(1) frame.lineno.should eq(1)
frame.column.should eq(7) frame.column.should eq(7)
frame.method.should eq("foo_bar?") frame.method.should eq("foo_bar?")
frame.file.should eq(path) frame.path.should eq(path)
frame.relative_path.should eq("lib/bar/src/bar.cr") frame.relative_path.should eq("lib/bar/src/bar.cr")
frame.under_src_path?.should be_true frame.under_src_path?.should be_true
frame.shard_name.should eq "bar" frame.shard_name.should eq "bar"
@ -186,7 +186,7 @@ describe Backtracer::Backtrace::Frame do
frame.lineno.should eq(1) frame.lineno.should eq(1)
frame.column.should eq(7) frame.column.should eq(7)
frame.method.should eq("foo_bar?") frame.method.should eq("foo_bar?")
frame.file.should eq(path) frame.path.should eq(path)
frame.relative_path.should eq(path) frame.relative_path.should eq(path)
frame.under_src_path?.should be_false frame.under_src_path?.should be_false
frame.shard_name.should eq "bar" frame.shard_name.should eq "bar"

View file

@ -1,31 +1,31 @@
module Backtracer module Backtracer
# An object representation of a stack frame. # An object representation of a stack frame.
struct Backtrace::Frame struct Backtrace::Frame
# The method of the frame (such as `User.find`). # The method of this frame (such as `User.find`).
getter method : String getter method : String
# The file portion of the frame (such as `app/models/user.cr`). # The file name of this frame (such as `app/models/user.cr`).
getter file : String? getter path : String?
# The line number portion of the frame. # The line number of this frame.
getter lineno : Int32? getter lineno : Int32?
# The column number portion of the frame. # The column number of this frame.
getter column : Int32? getter column : Int32?
protected getter(configuration) { Backtracer.configuration } protected getter(configuration) { Backtracer.configuration }
def initialize(@method, @file = nil, @lineno = nil, @column = nil, *, def initialize(@method, @path = nil, @lineno = nil, @column = nil, *,
@configuration = nil) @configuration = nil)
end end
def_equals_and_hash @method, @file, @lineno, @column def_equals_and_hash @method, @path, @lineno, @column
# Reconstructs the frame in a readable fashion # Reconstructs the frame in a readable fashion
def to_s(io : IO) : Nil def to_s(io : IO) : Nil
io << '`' << @method << '`' io << '`' << @method << '`'
if @file if @path
io << " at " << @file io << " at " << @path
io << ':' << @lineno if @lineno io << ':' << @lineno if @lineno
io << ':' << @column if @column io << ':' << @column if @column
end end
@ -39,11 +39,11 @@ module Backtracer
def under_src_path? : Bool def under_src_path? : Bool
return false unless src_path = configuration.src_path return false unless src_path = configuration.src_path
!!file.try(&.starts_with?(src_path)) !!path.try(&.starts_with?(src_path))
end end
def relative_path : String? def relative_path : String?
return unless path = file return unless path = @path
return path unless path.starts_with?('/') return path unless path.starts_with?('/')
return unless under_src_path? return unless under_src_path?
if prefix = configuration.src_path if prefix = configuration.src_path
@ -52,7 +52,7 @@ module Backtracer
end end
def absolute_path : String? def absolute_path : String?
return unless path = file return unless path = @path
return path if path.starts_with?('/') return path if path.starts_with?('/')
if prefix = configuration.src_path if prefix = configuration.src_path
File.join(prefix, path) File.join(prefix, path)
@ -66,7 +66,7 @@ module Backtracer
end end
def in_app? : Bool def in_app? : Bool
!!(file.try(&.matches?(configuration.in_app_pattern))) !!(path.try(&.matches?(configuration.in_app_pattern)))
end end
def context(context_lines : Int32? = nil) : {Array(String), String, Array(String)}? def context(context_lines : Int32? = nil) : {Array(String), String, Array(String)}?
@ -74,9 +74,9 @@ module Backtracer
return unless context_lines && (context_lines > 0) return unless context_lines && (context_lines > 0)
return unless (lineno = @lineno) && (lineno > 0) return unless (lineno = @lineno) && (lineno > 0)
return unless (filename = @file) && File.readable?(filename) return unless (path = @path) && File.readable?(path)
lines = File.read_lines(filename) lines = File.read_lines(path)
lineidx = lineno - 1 lineidx = lineno - 1
if context_line = lines[lineidx]? if context_line = lines[lineidx]?
@ -88,7 +88,7 @@ module Backtracer
def context_hash(context_lines : Int32? = nil) : Hash(Int32, String)? def context_hash(context_lines : Int32? = nil) : Hash(Int32, String)?
return unless context = self.context(context_lines) return unless context = self.context(context_lines)
return unless lineno = self.lineno return unless lineno = @lineno
pre_context, context_line, post_context = context pre_context, context_line, post_context = context