Author Topic: Logging Errors and exceptional cases in ARCed  (Read 2919 times)

Offline Ryex

  • Arctic Bird of Programming
  • Global Moderator
  • Chaos Ultimate
  • ****
  • Posts: 5131
  • LV: 197
  • Gender: Male
  • Wants to write a compiler for fun
    • View Profile
Logging Errors and exceptional cases in ARCed
« on: October 02, 2011, 02:34:23 AM »
The Kernel module is now equipped with a "Log" function that writes messages to a log file.

Code: [Select]
Kernel.Log(message=None, prefix="[Kernel]", error=False)
it generates a time stamp and uses the provided prefix to create a message

so a call like this

Code: [Select]
Kernel.Log("message goes here", "[Prefix]")
will create this message

Code: [Select]
MON 24 SET 2011 15:32:19 [GMT] [Prefix] message goes here
it also has a additional option argument that will attach a trace back of the latest error to be raised to the message

so a call like this

Code: [Select]
Kernel.Log("message goes here", "[Prefix]", True)
will create a message like this

Code: [Select]
MON 24 SET 2011 15:32:19 [GMT] [Prefix] message goes here [Error] Traceback
all the arguments are optional and if Message is left as None error will be set to true.

so a call
Code: [Select]
Kernel.Log()
will generate the following message
Code: [Select]
MON 24 SET 2011 15:32:19 [GMT] [Kernel] [Error] Traceback
so, when working on the editor:
  • Think of EVERYTHING that could go wrong, and create a exception for it if the error can be handled then and there. Use if elif else branches or try except finally statements  to cache the case and use Kernel.Log to record the event, and attach the latest error if you just caught an exception.
  • Use an informative Prefix that will tell what part of the system the message came from when logging these messages
  • if an error can't be handled properly. ie. the error will cause problems with other components, let it go up to the main wx.loop where it will be caught by the Wx library. ARCed will tap the Wx main loop error caching to log the error. but this is not yet implemented


messages are written to ARCed.log in the program folder
« Last Edit: October 02, 2011, 02:49:19 AM by Ryex »
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.

DropBox, the best free file syncing service there is.
(click to show/hide)

Offline Blizzard

  • This sexy
  • Administrator
  • has over 9000 posts
  • *****
  • Posts: 19916
  • LV: 642
  • Gender: Male
  • Magic midgets.
    • View Profile
    • You're already on it. (-_-')
Re: Logging Errors and exceptional cases in ARCed
« Reply #1 on: October 02, 2011, 09:35:58 PM »
messages are written to ARCed.log in the program folder

Bad idea. Better write here:

Code: (Windows XP) [Select]
%ALLUSERSPROFILE%\Application Data\ARCed\
Code: (Windows Vista / Windows 7) [Select]
%ALLUSERSPROFILE%\ARCed\
Get the proper environment variables by interfacing the kernel function GetEnvironmentW(). I can give you the wrapper code for that if you want.
Check out Daygames and our games:

King of Booze      King of Booze: Never Ever      Pet Bots
Drinking Game for Android      Never have I ever for Android      Pet Bots for Android
Drinking Game for iOS      Never have I ever for iOS      Pet Bots for iOS
Drinking Game on Steam


Quote from: winkio
I do not speak to bricks, either as individuals or in wall form.

Quote from: Barney Stinson
When I get sad, I stop being sad and be awesome instead. True story.

Offline Ryex

  • Arctic Bird of Programming
  • Global Moderator
  • Chaos Ultimate
  • ****
  • Posts: 5131
  • LV: 197
  • Gender: Male
  • Wants to write a compiler for fun
    • View Profile
Re: Logging Errors and exceptional cases in ARCed
« Reply #2 on: October 02, 2011, 10:40:31 PM »
Ok, I'll change that. any particular reason it's a bad Idea to save it in the local directory?
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.

DropBox, the best free file syncing service there is.
(click to show/hide)

Offline Blizzard

  • This sexy
  • Administrator
  • has over 9000 posts
  • *****
  • Posts: 19916
  • LV: 642
  • Gender: Male
  • Magic midgets.
    • View Profile
    • You're already on it. (-_-')
Re: Logging Errors and exceptional cases in ARCed
« Reply #3 on: October 02, 2011, 10:46:25 PM »
Premission problems. Windows won't allow you to write in Program Files or some similar folder because of that. All applications should put their stuff in "C:\Documents and Settings\Application Data" on XP and "C:\ProgramData" on 7 (where the environment variable ALLUSERSPROFILE comes into play). You will notice that pretty much all half-decent applications will put their stuff in there.
Check out Daygames and our games:

King of Booze      King of Booze: Never Ever      Pet Bots
Drinking Game for Android      Never have I ever for Android      Pet Bots for Android
Drinking Game for iOS      Never have I ever for iOS      Pet Bots for iOS
Drinking Game on Steam


Quote from: winkio
I do not speak to bricks, either as individuals or in wall form.

Quote from: Barney Stinson
When I get sad, I stop being sad and be awesome instead. True story.

Offline Ryex

  • Arctic Bird of Programming
  • Global Moderator
  • Chaos Ultimate
  • ****
  • Posts: 5131
  • LV: 197
  • Gender: Male
  • Wants to write a compiler for fun
    • View Profile
Re: Logging Errors and exceptional cases in ARCed
« Reply #4 on: October 02, 2011, 10:51:39 PM »
*face palm* of course. That makes perfect sense.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.

DropBox, the best free file syncing service there is.
(click to show/hide)

Offline Ryex

  • Arctic Bird of Programming
  • Global Moderator
  • Chaos Ultimate
  • ****
  • Posts: 5131
  • LV: 197
  • Gender: Male
  • Wants to write a compiler for fun
    • View Profile
Re: Logging Errors and exceptional cases in ARCed
« Reply #5 on: October 04, 2011, 08:06:16 AM »
ok, the folder name will be retreved with
Code: [Select]
wx.StandardPaths.Get().GetConfigDir() it returns the proper OS dependent path
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.

DropBox, the best free file syncing service there is.
(click to show/hide)

Offline Ryex

  • Arctic Bird of Programming
  • Global Moderator
  • Chaos Ultimate
  • ****
  • Posts: 5131
  • LV: 197
  • Gender: Male
  • Wants to write a compiler for fun
    • View Profile
Re: Logging Errors and exceptional cases in ARCed
« Reply #6 on: October 24, 2011, 05:53:33 AM »
Ok. I implemented Kernel.Protect.
basicly you encase a function object like so
Code: [Select]
Kernel.protect(func_obj) and it will catch any raised errors and log them with Kernel.Log and Kernel.Log will in turn inform the user of the error with a message box IF the wx.app has been created.

so a normal function call looks like this
Code: [Select]
self.func_obj(*args)a protected function call would look like this
Code: [Select]
Kernel.Protect(self.func_obj)(*args)
it is particularly important when a function is called by a wxpython event as once an error has been raised and passes into a C++ wxpthon portion of the call stack it can't be caught anymore. wxpython will catch the error print it to stdout and try to continue as if nothing happened if the error isn't caught before this point.

so when binding a function to a wxpython event if the function could reasonably throw an error wrap the function with Kernel.Protect like so
Code: [Select]
self.Bind(wx.EVT_X, Kernel.Protect(self.OnEventX))instead of the normal Bind call
Code: [Select]
self.Bind(wx.EVT_X, self.OnEventX)
« Last Edit: October 24, 2011, 05:55:23 AM by Ryex »
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.

DropBox, the best free file syncing service there is.
(click to show/hide)

Offline Ryex

  • Arctic Bird of Programming
  • Global Moderator
  • Chaos Ultimate
  • ****
  • Posts: 5131
  • LV: 197
  • Gender: Male
  • Wants to write a compiler for fun
    • View Profile
Re: Logging Errors and exceptional cases in ARCed
« Reply #7 on: September 01, 2014, 04:57:21 AM »
ok, so this might seem a bit stupid, reviving this topic for such a seemingly redundant question but I was looking at the code to day and I saw I was using ALLUSERSPROFILE, why not use APPDATA?
most applications I see now days use APPDATA (C:\Users\<NAME>\AppData\Roaming)
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.

DropBox, the best free file syncing service there is.
(click to show/hide)