From: eregontp@... Date: 2020-09-24T09:39:03+00:00 Subject: [ruby-core:100098] [Ruby master Feature#10561] Improve function of Thread::Backtrace::Location #path and #absolute_path Issue #10561 has been updated by Eregon (Benoit Daloze). There is an extra difference that #absolute_path will also try to canonicalize the path and resolve symlinks, so then even if #path is absolute, #absolute_path can be different. See https://github.com/ruby/spec/blob/e829fb0bcb667013f3527142b9e29883f6904537/core/thread/backtrace/location/absolute_path_spec.rb#L39-L69 So in short #path is the same as `__FILE__`. #absolute_path is essentially File.realpath(#path) + it seems to work on CRuby even if the file was removed. For eval(code, binding, file, line) code, #path and #absolute_path just return `file` and do not expand it, so it can be a relative path if `file` is relative. ---------------------------------------- Feature #10561: Improve function of Thread::Backtrace::Location #path and #absolute_path https://bugs.ruby-lang.org/issues/10561#change-87668 * Author: sam.saffron (Sam Saffron) * Status: Open * Priority: Normal ---------------------------------------- I was working on this issue in Rails and hit an area where Backtrace Location can be improved https://github.com/rails/rails/pull/17782 1. It is undefined in the documentation how #absolute_path should operate when #path is invalid (in case of instance eval) 2. There are a few conditions where #path and #absolute_path can return nil, this forces extra protection code when parsing paths to check for nil. (for example getting filename) Suggestions: 1. Instead of returning Qnil from location_path and location_absolute_path on invalid conditions, return the string "(unknown)" which is easier to parse and sticks out better in a big backtrace. There is precedent here with the string "(eval)" 2. If path is invalid have absolute_path return "(unknown)", define that in the documentation 3. (possible) add an additional method on caller_location called #filename so people stop parsing filename from #path and #absolute_path 4. Evaluate if it makes sense to have #path and #absolute_path in the API as both methods can return full paths so the semantic difference is subtle. -- https://bugs.ruby-lang.org/ Unsubscribe: