How to get class name from Scripts.rxdata? - MechanicalPen - 07-31-2013
I am trying to port Hime's Full Error Backtrace script to RPGmXP (this one)
It works fine as is (as long as you have that recently posts Console script) except that I get things like "Section086" instead of "Game_Player" so I can assume it is stored in a different place in scripts.rxdata.
here is the code if it helps (add it into the Main method)
Code: rescue Exception => error #Exception => error
scripts_name = load_data('Data/Scripts.rxdata')
scripts_name.collect! {|script| script[1] }
backtrace = []
error.backtrace.each_with_index {|line,i|
if line =~ /{(.*)}(.*)/
backtrace << (scripts_name[$1.to_i] + $2)
elsif line =~ /\A:1:/
break
else
backtrace << line
end
}
error_line = backtrace.first
backtrace[0] = ''
out_string = error_line + ": " + error.message + " (#{error.class})" + backtrace.join("\n\tfrom ") + "\n"
console.log( out_string)
raise error.class, "Error ocurred, check the debug console for more information.", [error.backtrace.first]
RE: How to get class name from Scripts.rxdata? - Ryaryu - 08-13-2013
Do you really need that backtracing script?
I have one in my project, i really don't know the scripter name (sorry dude), but the script helps me greatly: it shows the backtrace, the script names, the line and method called. And i'm writing a CMS \ CBS in my game.
Hope it helps.
To install it, just change this part of Main script...
Code: rescue Errno::ENOENT
# Aqui, definimos a mensagem padrão para Errno::ENOENT
# Quando não é possível abrir um arquivo, a mensagem é exibida
filename = $!.message.sub("Arquivo não encontrado - ", "")
print("O Arquivo #{filename} não foi encontrado.")
end
For this.
Code: rescue Errno::ENOENT
# Aqui, definimos a mensagem padrão para Errno::ENOENT
# Quando não é possível abrir um arquivo, a mensagem é exibida
filename = $!.message.sub("Arquivo não encontrado - ", "")
print("O Arquivo #{filename} não foi encontrado.")
rescue StandardError => stderr
# Bring message to user that an error has occured
p "Your error message here. See Instructions for more details."
# Optional, when debugging, you will still receive the error message, but in less details.
if $DEBUG
p stderr.message
end
# When?
time = Time.now
time = time.strftime("%a %d %b %Y, %X")
# Write to file
File.open("ErrorLog.rxdata","a+") do |fh|
# Time
fh.puts("Time: #{time}")
# Error type
fh.puts("Error type: #{stderr.class}")
# In which class?
fh.puts("Class: #{$scene.class}")
# Message
fh.puts("Message: #{stderr.message}")
# Where?
fh.puts("at")
for location in stderr.backtrace
# Get the section number
section = location[/(?#Section)(\d)*(:)/]
# Strip off anything but numbers
section_err = section[0, section.length - 1]
script_name = $RGSS_SCRIPTS[section_err.to_i][1]
# Get line number
line_num = location[/(:)(\d)*(\Z|(:))/]
# Strip off anything but line number
#line_num_err = line_num[section_err.length + 1, line_num.length - section_err.length]
# Strip off ":" if any
line_num_err = line_num[1, line_num.length - 1]
line_num_err = line_num_err[/(\d)*/]
# If any, get method name
method = location[/\s\W(\w)*\W/]
# Strip the space
method = method[1, method.length - 1] unless method == nil
# Now construct location string
loc_err = script_name + ", line " + line_num_err +
(method == nil ? "" : ", at " + method)
# Write to file
fh.puts(" #{loc_err}")
end
# Delimiter
fh.puts("--------------------")
end
end
The backtrace is saved in the file ErrorLog.rxdata in the project's root directory. Its a stream of characters, so any text editor can read it's data (Notepad, Wordpad, Notepad++, Sublime Text, etc).
RE: How to get class name from Scripts.rxdata? - MechanicalPen - 08-13-2013
That's what I was looking for: "script_name = $RGSS_SCRIPTS[section_err.to_i][1]"
Thanks!
|