Error reporting extension!
#1
Here is a handy script I made a while ago to give more detailed error reports and print them to the console! It gives a full trace of where the error happened and the last called functions so you know what the problem might be! Has some limitations. Sometimes the report is too big for the little popup and it will be blank, but it should show the error in the console! Also doesn't properly trace errors inside events, so that might be something to add later.

Oh! And you can use "Error_Handler.do_trace()" to print a backtrace to the console in scripts whenever you want for debugging too!

Code:
#==============================================================================
# * Error handling functions.
#==============================================================================

module Error_Handler
 
  def self.script_names
    unless @script_names
      @script_names = load_data('Data/Scripts.rvdata2')
      @script_names.collect! {|script|  script[1]  }
    end
    @script_names
  end
 
  def self.do_backtrace(error)
    backtrace = self.parse_trace(error.backtrace)
    error_line = backtrace.first
    backtrace[0] = ''
    return error_line + ": " + error.message + " (#{error.class})" + backtrace.join("\n\tfrom ") + "\n"
  end
 
  def self.parse_trace(trace)
    out = []
    trace.each_with_index do |line,i|
      if line =~ /{(.*)}(.*)/
        out << (script_names[$1.to_i] + $2)
      elsif line.start_with?(':1:')
        break
      else
        out << line
      end
    end
    out
  end
 
  def trace_me
    begin
      raise
    rescue => exception
      puts trace = Error_Handler.do_backtrace(exception)
    end
  end
 
end

alias rgss_main_without_rescue rgss_main

def rgss_main(&block)
  begin
    rgss_main_without_rescue do
      begin
        block.call
      rescue SystemExit
        exit
      rescue Exception => error
        trace = Error_Handler.do_backtrace(error)
        print(trace)
        raise(error.class, trace, [error.backtrace.first])
      end
    end
  end

end

Hope it's helpful!
Reply
#2
Thinking Just my 5 cents here. Did you know that the $RGSS_SCRIPTS variable already contains the scripts data?
I mean, there's no need to load the Scripts.rvdata2 file or the equivalent in RMXP and RMVX. You would just need to extract the script's actual code from each array slot like you already do it in line 10.
"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9

Maranatha!

The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.

[Image: SP1-Scripter.png]
[Image: SP1-Writer.png]
[Image: SP1-Poet.png]
[Image: SP1-PixelArtist.png]
[Image: SP1-Reporter.png]

My Original Stories (available in English and Spanish)

List of Compiled Binary Executables I have published...
HiddenChest & Roole

Give me a free copy of your completed game if you include at least 3 of my scripts! Laughing + Tongue sticking out

Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE
Reply
#3
I didn't know! :o

Edit: Wonder if I could make it compatible with vx and xp actually... don't think rgss_main exists on xp and might not in vx either and overwriting main is a pain...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
   File Missing Error Preventer xnadvance 0 1,671 05-31-2011, 06:04 AM
Last Post: xnadvance
   Error Log PK8 0 1,836 04-03-2009, 01:31 AM
Last Post: PK8



Users browsing this thread: 1 Guest(s)