Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-11652] iOS: Add script errors/stack trace to TiExceptionHandler data

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2013-01-16T10:19:40.000+0000
Affected Version/sRelease 3.0.0
Fix Version/sRelease 3.0.2, Release 3.1.0, 2012 Sprint 23 API, 2012 Sprint 23
ComponentsCore
Labelsexception, qe-port, triage
ReporterMax Stepanov
AssigneeBlain Hamon
Created2012-11-02T17:16:43.000+0000
Updated2014-07-06T20:11:52.000+0000

Description

JavaScript:
// Without try catch:
var err = new Error("My Awesome Caught Error!");
API.logHandledException(err);

try {
var err = new Error("My Awesome Caught Error!");
throw err

} catch (err){
API.logHandledException(err);
}
Objective-C:
-(void)logHandledException:(id)args
{
    TiLogMessage([NSString stringWithFormat:@"class type?: %@", [[args objectAtIndex:0] class]]); // This returns as NSDictionary, is this expected?

//    TiScriptError *exception = [TiScriptError initWithDictionary:[args objectAtIndex:0]]; // This selector doesn't exist?
    TiScriptError *exception = (TiScriptError *)args; // Returns an array, not a single object. In other methods, they returned the objects rather than an array of parameters.

[API logHandledException:[self convertScriptErrorToNative:exception]];
}

Comments

  1. Blain Hamon 2013-01-15

    Reopening so that we can bring TiJSCore in. Also, documentation.
  2. Max Stepanov 2013-01-26

    A test case:
       var win1 = Titanium.UI.createWindow({ backgroundColor:'#fff' });
        
       var accessor = {};
       accessor.buildEmailView = function(to, subject, defaultBody) {
         
           var emailDialog = Ti.UI.createEmailDialog();
           emailDialog.setSubject(subject);
           emailDialog.setToRecipients(to);
           emailDialog.setMessageBody(defaultBody);
           emailDialog.setHtml(true);
           emailDialog.setBarColor('#312f2c');
            
            emailDialog.open();
            
           emailDialog.addEventListener('complete',function(e)
           {
               if (e.result == emailDialog.SENT)
               {
                   alert("message was sent");
               }
               else
               {
                   alert("message was not sent. result = "+e.result);
               }
           });
         
       };
       accessor.buildEmailView(/* to */ 'email@appc.com', /* subject */ 'Testing', /* defaultBody */ 'DefaultBody');
        
       win1.open();
       
    Output will be something like:
       [ERROR] Script Error {
           backtrace = "#0 () at file://localhost/Users/max/Library/Application%20Support/iPhone%20Simulator/4.3.2/Applications/86EAB896-F4E9-4672-9426-D20F7FAED5F1/Titanium.app/app.js:29";
           line = 13;
           message = "Invalid type passed to function";
           nativeLocation = "-[TiUIEmailDialogProxy open:] (TiUIEmailDialogProxy.m:63)";
           nativeReason = "expected: NSArray or nil, was: NSCFString";
           sourceId = 208722560;
           sourceURL = "file://localhost/Users/max/Library/Application%20Support/iPhone%20Simulator/4.3.2/Applications/86EAB896-F4E9-4672-9426-D20F7FAED5F1/Titanium.app/app.js";
       }
       
    The expected result should contain valid 'backtrace' property:value pair.
  3. Olga Romero 2013-01-26

    Closing. Tested and verified fix with: Device: iPhone5 iOS 6.0 Titanium Studio, build: 3.0.1.201212181159 Titanium SDK, build: 3.0.2.v20130125153221 Titanium SDK, build:3.1.0.v20130125152545 Similar output.

JSON Source