2

The new version AIR gives us the ability to globally capture run time errors and handle them. The problem is that it doesn't have the stacktrace or any helpful information about the error other than the error id and error message and name. For example it may tell me that a null pointer exception has happened but it will not tell me where or which method or anything. The debug version of the runtime gives us all of that but when the app is deployed to customers it is not running on the debug version so none of the useful information is available. I was wondering if this group has any suggestions on how to enable better logging of errors in an AIR app for better supportability of the product. Any suggestions?

Saviz
  • 677
  • 6
  • 19

4 Answers4

5

I have a little hack to get line numbers too. :)

  1. make a listener to get uncaught errors. I do it in my main class:

    private function addedToStageHandler(event:Event):void {
        loaderInfo.uncaughtErrorEvents.addEventListener( UncaughtErrorEvent.UNCAUGHT_ERROR, uncaughtErrorHandler );
    }
    
  2. for example my listener with error.getStackTrace():

    private function uncaughtErrorHandler( event:UncaughtErrorEvent ):void
    {
        var errorText:String;
        var stack:String;
        if( event.error is Error )
        {
            errorText = (event.error as Error).message;
            stack = (event.error as Error).getStackTrace();
            if(stack != null){
                errorText += stack;
            }
        } else if( event.error is ErrorEvent )
        {
            errorText = (event.error as ErrorEvent).text;
        } else
        {
            errorText = event.text;
        }
        event.preventDefault();
        Alert.show( errorText + " " + event.error, "Error" );
    }
    
  3. Add additional compiler argument: -compiler.verbose-stacktraces=true

  4. Create the release build.
  5. now the little hack: Mac: Go to the installation location where you have your .app file. Right click and choose show package content. Navigate to Contents ▸ Resources ▸ META-INF ▸ AIR. There you can find a file called hash. Duplicate the hash file and rename it to debug. Open the debug file with some text editor and remove the content. Done now you get the stack trace + line numbers. Windows: Browse to its install directory in a file explorer. Navigate to {app-folder}▸META-INF▸AIR▸. Here you can find a file called hash. Duplicate the hash file and rename it to debug. Open the debug file with some text editor and remove the content. Done now you get the stack trace + line numbers.

If you can't find the hash file, just create an empty file without file extension and call it debug.

Tested with Air 3.6!

Math
  • 3,334
  • 4
  • 36
  • 51
Stefan Habacher
  • 153
  • 1
  • 8
  • How ever you tracked this down, thank you. No wonder Adobe has shot themselves in the a$$ with the Flash / Flex / AIR platform. – Mike Petty Dec 09 '14 at 00:29
  • I'm afraid it doesn't work. I think you were using a debug build and that's why it worked. With -debug=false you still won't get the line numbers, even with this hack. – b005t3r Sep 07 '16 at 07:25
1

The compiler option:

compiler.verbose-stacktraces=true

should embed stack information even in a non-debug build.

kpatelPro
  • 287
  • 2
  • 10
  • do you put this option in Project Settings -> Flex Compiler -> Additional compiler arguments? If so, do you prefix it with a dash like so -compiler.verbose-stacktraces=true or no dash? I have tried every possible combination of this but I still don't get stack traces in my release builds! – Jason Dec 14 '12 at 00:03
  • Jason same here inmy case, i couldt trace in that mode, i need some solution for that. – gaurav_gupta Dec 23 '13 at 10:16
  • It doesn't do the trick, I'm afraid. You need a debug build to do it, there's no other way currently that I know of. – b005t3r Sep 07 '16 at 07:29
1

No way until new version of AIR supports it. It doesn't now because of performance issues, rendering global handler almost useless. I'm waiting for it too, because alternative is logging everything yourself, and this is very time consuming.

alxx
  • 9,897
  • 4
  • 26
  • 41
0

About the compiler option. I develop with IntelliJ IDEA 14. In my build options i have also "Generate debuggable SWF". Maybe thats the reason why its working. Check my attachment. Grettings enter image description here

Stefan Habacher
  • 153
  • 1
  • 8