def process_ex
window_size = Pry.config.default_window_size || 5
ex = _pry_.last_exception
raise CommandError, "No exception found." unless ex
if opts[:ex].nil?
bt_index = ex.bt_index
ex.inc_bt_index
else
bt_index = opts[:ex]
end
ex_file, ex_line = ex.bt_source_location_for(bt_index)
raise CommandError, "The given backtrace level is out of bounds." unless ex_file
if RbxPath.is_core_path?(ex_file)
ex_file = RbxPath.convert_path_to_full(ex_file)
end
set_file_and_dir_locals(ex_file)
start_line = ex_line - window_size
start_line = 1 if start_line < 1
end_line = ex_line + window_size
header = unindent "\#{text.bold 'Exception:'} \#{ex.class}: \#{ex.message}\n--\n\#{text.bold('From:')} \#{ex_file} @ line \#{ex_line} @ \#{text.bold(\"level: \#{bt_index}\")} of backtrace (of \#{ex.backtrace.size - 1}).\n\n"
code = yield(Pry::Code.from_file(ex_file).
between(start_line, end_line).
with_marker(ex_line))
"#{header}#{code}"
end