Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26369] iOS: unhandledException Ti.App event no longer working.

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2018-09-22T15:05:24.000+0000
Affected Version/sRelease 7.3.0
Fix Version/sRelease 7.5.0
ComponentsiOS
Labelsn/a
ReporterRichard Lustemberg
AssigneeHans Knöchel
Created2018-09-06T10:25:41.000+0000
Updated2019-05-01T20:25:45.000+0000

Description

When stack traces where added to the display of unhandled exceptions in May 2018, the functionality was removed. I can provide a PR to fix that. Files that need to be modified: AppModule.m , line 368
[nc addObserver:self selector:@selector(errored:) name:kTiErrorNotification object:nil];
TiExceptionHandler.m , line 58
- (void)showScriptError:(TiScriptError *)error
{
  NSArray<NSString *> *exceptionStackTrace = [NSThread callStackSymbols];

  if (exceptionStackTrace == nil) {
    [[TiApp app] showModalError:[error description]];
    [[NSNotificationCenter defaultCenter] postNotificationName:kTiErrorNotification
                                                        object:self
                                                      userInfo:error.dictionaryValue];
  } else {
    NSMutableArray<NSString *> *formattedStackTrace = [[[NSMutableArray alloc] init] autorelease];
    NSUInteger exceptionStackTraceLength = [exceptionStackTrace count];

    // re-size stack trace and format results. Starting at index = 4 to not include the script-error API's
    for (NSInteger i = 4; i < (exceptionStackTraceLength >= 20 ? 20 : exceptionStackTraceLength); i++) {
      NSString *line = [[exceptionStackTrace objectAtIndex:i] stringByReplacingOccurrencesOfString:@"     " withString:@""];
      [formattedStackTrace addObject:line];
    }

    NSString *stackTrace = [formattedStackTrace componentsJoinedByString:@"\n"];
    [[TiApp app] showModalError:[NSString stringWithFormat:@"%@\n\n%@", [error description], stackTrace]];
    NSMutableDictionary *errorDict = [error.dictionaryValue mutableCopy];
    [errorDict setObject:stackTrace forKey:@"stackTrace"];
    [[NSNotificationCenter defaultCenter] postNotificationName:kTiErrorNotification
                                                        object:self
                                                      userInfo:errorDict];
  }
}

Comments

  1. Sharif AbuDarda 2018-09-07

    Hello, please assign the PR to this ticket. Moving it to engineering. Thanks
  2. Richard Lustemberg 2018-09-07

    Done :)
  3. Samir Mohammed 2018-10-17

    *Closing ticket.* Verified fix in SDK Version 7.5.0.v20181016071050 Tested using the following test case:
       Ti.App.addEventListener('uncaughtException', function(evt) {
           alert({
               // Both iOS and Android:
               message: evt.message,
               line: evt.line,
       
               // iOS Only:
               sourceId: evt.sourceId,
               type: evt.type,
               sourceURL: evt.sourceURL,
               backtrace: String(evt.backtrace).substr(0, 100) + '...',
       
               // Android Only:
               title: evt.title,
               sourceName: evt.sourceName,
               lineSource: evt.lineSource,
               lineOffset: evt.lineOffset
           });
       });
       
       throw new Error('Hello, error handler!');
    Able to see:
       [DEBUG] :  Firing app event: uncaughtException
       
    This was not visible before this fix. *Test Environment*
       APPC Studio: 5.1.0.201808080937
       iPhone 6 Sim (iOS 12)
       APPC CLI: 7.0.6
       Operating System Name: Mac OS Mojave
       Operating System Version: 10.14
       Node.js Version: 8.9.1
       Xcode 10.0
  4. Leonardo Amigoni 2019-05-01

    I'm still seeing this issue in 8.0. It was firing for a while but not it doesn't seem to. Unfortunately I can't seem to reproduce the case where it was firing. Android works fine iOS doesn't

JSON Source