Fixed inconsistencies in error messages produced when loading a plugin

This commit is contained in:
Maruno17
2022-01-22 22:03:31 +00:00
parent 7f0526114f
commit 8a3e5b01e0

View File

@@ -440,24 +440,17 @@ module PluginManager
# formats the error message # formats the error message
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
def self.pluginErrorMsg(name, script) def self.pluginErrorMsg(name, script)
e = $!
# begin message formatting # begin message formatting
message = "[Pokémon Essentials version #{Essentials::VERSION}]\r\n" message = "[Pokémon Essentials version #{Essentials::VERSION}]\r\n"
message += "#{Essentials::ERROR_TEXT}\r\n" # For third party scripts to add to message += "#{Essentials::ERROR_TEXT}\r\n" # For third party scripts to add to
message += "Error in Plugin [#{name}]:\r\n" message += "Error in Plugin: [#{name}]\r\n"
message += "#{$!.class} occurred.\r\n" message += "Exception: #{e.class}\r\n"
# go through message content message += "Message: "
$!.message.split("\r\n").each do |line| message += e.message
next if nil_or_empty?(line)
n = line[/\d+/]
err = line.split(":")[-1].strip
lms = line.split(":")[0].strip
err.gsub!(n, "") if n
linum = n ? "Line #{n}: " : ""
message += "#{linum}#{err}: #{lms}\r\n"
end
# show last 10 lines of backtrace # show last 10 lines of backtrace
message += "\r\nBacktrace:\r\n" message += "\r\n\r\nBacktrace:\r\n"
$!.backtrace[0, 10].each { |i| message += "#{i}\r\n" } e.backtrace[0, 10].each { |i| message += "#{i}\r\n" }
# output to log # output to log
errorlog = "errorlog.txt" errorlog = "errorlog.txt"
errorlog = RTP.getSaveFileName("errorlog.txt") if (Object.const_defined?(:RTP) rescue false) errorlog = RTP.getSaveFileName("errorlog.txt") if (Object.const_defined?(:RTP) rescue false)