module Byebug::Helpers::EvalHelper
def allowing_other_threads
will get blocked by byebug's main thread.
creating new threads won't be properly evaluated because new threads
Used to evaluate stuff within Byebug's prompt. Otherwise, any code
Run block temporarily ignoring all TracePoint events.
def allowing_other_threads Byebug.unlock res = yield Byebug.lock res end
def error_eval(str, binding = frame._binding)
handling the errors at an error level.
Evaluates a string containing Ruby code in a specific binding,
def error_eval(str, binding = frame._binding) safe_eval(str, binding) { |e| raise(e, msg(e)) } end
def error_msg(exception)
def error_msg(exception) at = exception.backtrace locations = ["#{at.shift}: #{warning_msg(exception)}"] locations += at.map { |path| " from #{path}" } locations.join("\n") end
def in_new_thread
returns the new thread's result.
Runs the given block in a new thread, waits for it to finish and
def in_new_thread res = nil Thread.new { res = yield }.join res end
def msg(exception)
def msg(exception) msg = Setting[:stack_on_error] ? error_msg(exception) : warning_msg(exception) pr("eval.exception", text_message: msg) end
def multiple_thread_eval(expression)
-
expression
(String
) -- Expression to evaluate
Other tags:
- Note: - This is necessary because when in byebug's prompt, every thread is
def multiple_thread_eval(expression) allowing_other_threads { warning_eval(expression) } end
def safe_eval(str, binding)
def safe_eval(str, binding) binding.eval(str.gsub(/\Aeval /, ""), "(byebug)", 1) rescue StandardError, ScriptError => e yield(e) end
def safe_inspect(var)
def safe_inspect(var) var.inspect rescue StandardError safe_to_s(var) end
def safe_to_s(var)
def safe_to_s(var) var.to_s rescue StandardError "*Error in evaluation*" end
def separate_thread_eval(expression)
-
expression
(String
) -- Expression to evaluate
def separate_thread_eval(expression) allowing_other_threads do in_new_thread { warning_eval(expression) } end end
def silent_eval(str, binding = frame._binding)
returning nil in an error happens.
Evaluates a string containing Ruby code in a specific binding,
def silent_eval(str, binding = frame._binding) safe_eval(str, binding) { |_e| nil } end
def warning_eval(str, binding = frame._binding)
handling the errors at a warning level.
Evaluates a string containing Ruby code in a specific binding,
def warning_eval(str, binding = frame._binding) safe_eval(str, binding) { |e| errmsg(msg(e)) } end
def warning_msg(exception)
def warning_msg(exception) "#{exception.class} Exception: #{exception.message}" end