Changed the content of error messages raised by code in a Script event command

This commit is contained in:
Maruno17
2021-07-23 20:06:06 +01:00
parent 912631a8b1
commit a1cff9cc36
2 changed files with 49 additions and 53 deletions

View File

@@ -4,7 +4,17 @@
class Reset < Exception
end
class EventScriptError < Exception
attr_accessor :event_message
def initialize(message)
super(nil)
@event_message = message
end
end
def pbGetExceptionMessage(e,_script="")
return e.event_message.dup if e.is_a?(EventScriptError) # Message with map/event ID generated elsewhere
emessage = e.message.dup
emessage.force_encoding(Encoding::UTF_8)
if e.is_a?(Hangup)
@@ -18,27 +28,26 @@ def pbGetExceptionMessage(e,_script="")
end
def pbPrintException(e)
emessage = ""
if $EVENTHANGUPMSG && $EVENTHANGUPMSG!=""
emessage = $EVENTHANGUPMSG # Message with map/event ID generated elsewhere
$EVENTHANGUPMSG = nil
else
emessage = pbGetExceptionMessage(e)
end
emessage = pbGetExceptionMessage(e)
# begin message formatting
message = "[Pokémon Essentials version #{Essentials::VERSION}]\r\n"
message += "#{Essentials::ERROR_TEXT}\r\n" # For third party scripts to add to
message += "Exception: #{e.class}\r\n"
message += "Message: #{emessage}\r\n"
# show last 10/25 lines of backtrace
message += "\r\nBacktrace:\r\n"
btrace = ""
if e.backtrace
maxlength = ($INTERNAL) ? 25 : 10
e.backtrace[0, maxlength].each { |i| btrace += "#{i}\r\n" }
if !e.is_a?(EventScriptError)
message += "Exception: #{e.class}\r\n"
message += "Message: "
end
message += "#{emessage}"
# show last 10/25 lines of backtrace
if !e.is_a?(EventScriptError)
message += "\r\n\r\nBacktrace:\r\n"
backtrace_text = ""
if e.backtrace
maxlength = ($INTERNAL) ? 25 : 10
e.backtrace[0, maxlength].each { |i| backtrace_text += "#{i}\r\n" }
end
backtrace_text.gsub!(/Section(\d+)/) { $RGSS_SCRIPTS[$1.to_i][1] } rescue nil
message += backtrace_text
end
btrace.gsub!(/Section(\d+)/) { $RGSS_SCRIPTS[$1.to_i][1] } rescue nil
message += btrace
# output to log
errorlog = "errorlog.txt"
errorlog = RTP.getSaveFileName("errorlog.txt") if (Object.const_defined?(:RTP) rescue false)
@@ -55,7 +64,7 @@ def pbPrintException(e)
print("#{message}\r\nThis exception was logged in #{errorlogline}.\r\nHold Ctrl when closing this message to copy it to the clipboard.")
# Give a ~500ms coyote time to start holding Control
t = System.delta
until (System.delta - t) >= 500000
until (System.delta - t) >= 500_000
Input.update
if Input.press?(Input::CTRL)
Input.clipboard = message