lib/byebug/helpers/eval.rb in byebug-6.0.0 vs lib/byebug/helpers/eval.rb in byebug-6.0.1
- old
+ new
@@ -17,58 +17,60 @@
# Evaluates an +expression+ that doesn't deal with threads
#
# @param expression [String] Expression to evaluate
#
def single_thread_eval(expression)
- return error_eval(expression) if Setting[:stack_on_error]
-
warning_eval(expression)
end
#
# Evaluates a string containing Ruby code in a specific binding,
# returning nil in an error happens.
#
def silent_eval(str, binding = frame._binding)
- binding.eval(str)
- rescue StandardError, ScriptError
- nil
+ safe_eval(str, binding) { |_e| nil }
end
#
# Evaluates a string containing Ruby code in a specific binding,
# handling the errors at an error level.
#
def error_eval(str, binding = frame._binding)
- safe_eval(str, binding) { |e| error_msg(e) }
+ safe_eval(str, binding) { |e| fail(e, msg(e)) }
end
#
# Evaluates a string containing Ruby code in a specific binding,
# handling the errors at a warning level.
#
def warning_eval(str, binding = frame._binding)
- safe_eval(str, binding) { |e| warning_msg(e) }
+ safe_eval(str, binding) { |e| errmsg(msg(e)) }
end
private
def safe_eval(str, binding)
binding.eval(str)
rescue StandardError, ScriptError => e
- raise(e, yield(e))
+ yield(e)
end
+ def msg(e)
+ msg = Setting[:stack_on_error] ? error_msg(e) : warning_msg(e)
+
+ pr('eval.exception', text_message: msg)
+ end
+
def error_msg(e)
at = e.backtrace
- locations = ["#{at.shift}: #{e.class} Exception(#{e.message})"]
- locations += at.map { |path| "\tfrom #{path}" }
- pr('eval.exception', text_message: locations.join("\n"))
+ locations = ["#{at.shift}: #{warning_msg(e)}"]
+ locations += at.map { |path| "\tfrom #{path}" }
+ locations.join("\n")
end
def warning_msg(e)
- pr('eval.exception', text_message: "#{e.class} Exception: #{e.message}")
+ "#{e.class} Exception: #{e.message}"
end
#
# Run block temporarily ignoring all TracePoint events.
#