Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Error Log by Mr.Mo

Error Log and its uses!

If you receive any error in any part of the game, this script will capture it, and record it.

Useful for using it in compiled games, testing released scripts and just for having records of the errors you have received.

Instead of asking the players/testers/users for re-acting the error(s), you can just ask them send you this detailed file saved in their game's folder.

I made this little script for a project of mine.

Features

  • Records error message and type.
  • Records scripts with the error, error line, and method.
  • It traces the origination of the error to the line where the error is shown.
  • Records Date and Time.

Example Output

Code:
[COLOR=Blue][ Sun 25 Nov 2007, 01:12:44 ][/COLOR]
[COLOR=Red]'undefined method `values' for nil:NilClass' Type NoMethodError[/COLOR][COLOR=Green]
  <>Script '[LIB] Network Library' | Line 169 | Method `update'[/COLOR]
    <>Script 'Scene_Title' | Line 71 | Method `main'
      <>Script 'Scene_Title' | Line 69 | Method `loop'
        <>Script 'Scene_Title' | Line 82 | Method `main'
  1. First Line: Date and Time
  2. Second Line: The error message and type
  3. Third line: The line where the error is.
  4. Other lines: The lines where the data originated from, not the error.

Cons
If an error is from an hidden class or a class that overrides a hidden class, the line and method will not be shown, however, all other data will be present(such as original error line and script name). It would be very rare to have errors originate from hidden classes, so this is not bad.

Installing in 10 seconds

Open your Script Editor and go to Main. put a "begin" over all the way to the top, where the other begin is:

Snippet - Should look similar to this with 2 'begin'
Code:
#==============================================================================
# ** Main
#------------------------------------------------------------------------------
#  After defining each class, actual processing begins here.
#==============================================================================
[B]begin
begin[/B]
  # Prepare for transition
  Graphics.freeze
  # Make scene object (title screen)
  $scene = Scene_Title.new

Now, go all the way to end of that script(after end) and copy and paste this:
Code:
rescue
  # Record Error
  k = 0
  time = Time.now
  time = time.strftime("%a %d %b %Y, %X")
  log = File.open("ErrorLog.rxdata","a+")
  log.write("[ #{time} ]\n")
  # Write Message and Type
  log.write("'#{$!.message}' Type #{$!.class}\n")
  for i in 0..$!.backtrace.size
    e = $!.backtrace[i]
    /Section(.*):(.*):in (.*)/.match(e)
    space = " "*(i*2)
    log.write(space+"  <>Script '#{$RGSS_SCRIPTS[$1.to_i][1]}' | Line #{$2} | Method #{$3}\n")
    i += 1
    # Don't list more then 4 backtraces to make it simpler, can be changed! 
    break if i >= 4
    next if k == 1
    # Get the first trace
    script = "#{$RGSS_SCRIPTS[$1.to_i][1]}"
    line = $2
    method = $3
    k = 1
  end
  log.write("\n")
  log.close
  # Make some sense
  if $DEBUG
    print "#{$!.message} \nScript '#{script}' \nLine '#{line}' \nMethod '#{method}' \nType '#{$!.class}'"
  else
    print "Unexpected Error! Please visit www.site.com/support for more info.\n"+
        "The ErrorLog is in folder:\n #{File.expand_path('.')}"
  end
end

The whole thing should probably look like this:
Code:
#==============================================================================
# ** Main
#------------------------------------------------------------------------------
#  After defining each class, actual processing begins here.
#==============================================================================
[COLOR=Blue][B]begin[/B][/COLOR]
begin
  # Prepare for transition
  Graphics.freeze
  # Make scene object (title screen)
  $scene = Scene_Title.new
  # Call main method as long as $scene is effective
  while $scene != nil
    $scene.main
  end
  # Fade out
  Graphics.transition(20)
rescue Errno::ENOENT
  # Supplement Errno::ENOENT exception
  # If unable to open file, display message and end
  filename = $!.message.sub("No such file or directory - ", "")
  print("Unable to find file #{filename}.")
end[COLOR=Blue][B]
rescue
  # Record Error
  k = 0
  time = Time.now
  time = time.strftime("%a %d %b %Y, %X")
  log = File.open("ErrorLog.rxdata","a+")
  log.write("[ #{time} ]\n")
  # Write Message and Type
  log.write("'#{$!.message}' Type #{$!.class}\n")
  for i in 0..$!.backtrace.size
    e = $!.backtrace[i]
    /Section(.*):(.*):in (.*)/.match(e)
    space = " "*(i*2)
    log.write(space+"  <>Script '#{$RGSS_SCRIPTS[$1.to_i][1]}' | Line #{$2} | Method #{$3}\n")
    i += 1
    # Don't list more then 4 backtraces to make it simpler, can be changed! 
    break if i >= 4
    next if k == 1
    # Get the first trace
    script = "#{$RGSS_SCRIPTS[$1.to_i][1]}"
    line = $2
    method = $3
    k = 1
  end
  log.write("\n")
  log.close
  # Make some sense
  if $DEBUG
    print "#{$!.message} \nScript '#{script}' \nLine '#{line}' \nMethod '#{method}' \nType '#{$!.class}'"
  else
    print "Unexpected Error! Please visit www.site.com/support for more info.\n"+
        "The ErrorLog is in folder:\n #{File.expand_path('.')}"
  end
end[/B][/COLOR]

Finally

Once an error appears, the player sees this line:

print "Unexpected Error! Please visit http://www.site.com/support for more info.\n"+
"The ErrorLog is in folder:\n #{File.expand_path('.')}"


Which might not be what you want the player to see. So what you can do is, change it :-p. Here is an example of a different one:

print
"Unexpected Error! The ErrorLog is in folder:\n #{File.expand_path('.')}"

However, in Debug(Test Play), the message displays the error, error line and method.

To open the ErrorLog.rxdata file and see the errors:
1) Right Click
2) Open With
3) Note Pad

Credits

Credit to me. Feel free to use it in any project(commercial or not) as long as I'm mentioned.
 
So let me get this right Mo. This will hopefully make it easier to catch errors and fix them rather than going in changing up a little snippet of script and messing everything up completely yes? I'm just curious because I know nothing of scripting. I just mess with things until I get what I want and thats how I get the job done. But yeah not bad. I'll have to try this out! Good to see you back and posting. Keep it up man.
 
Well, the script just records the error's details. By doing so, people don't need to remember what the error was or recreate the error, they just open the file and copy and paste.

Its really useful for giving support for your scripts and game.

I'm not really back. I just had this script for a project of mine that I never finished and I thought it would be useful for people who want to debug and so on.

Update: Fixed some stuff that I overlooked last time :-p.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top