1

Is there a reason why console.error(error) (more precisely the error.message value) differs between iOS and Android in Ionic Angular app (cordova) ?

I wrote these lines to get an exception:

const a = null;
a.top();

then console.error(error) in my ErrorHandler.

The output for Android seems good but output for iOS is not clear enough. And I think this is the reason why the stack trace is not correctly built on Rollbar.

Example of output:

Android enter image description here

iOS enter image description here

Logs differ in terms on the trace, for Android each trace starts with 'at ...' and ends with file name but for iOS all the error goes on one line with 'step@' instead of 'at' and there is no link to go the file.

Anyone has an idea why this is the case.

  • Cordova: 10.0.0
  • cordova-ios: 6.1.0
  • Angular: 8.0.0

SOLUTION The error was thrown from an async method. Thus Angular's ErrorHandler catches error thrown from non awaited async methods and returns the error as a Promise.

Therefore in the handleError() method, add the line below

if (error.promise && error.rejection) { error = error.rejection; }
// handle your error

Found this solution thanks to: Angular custom error handler not getting error type from promise

Full answer below.

2 Answers 2

0

Basically, when you assign null value to an object and try to access any of it's properties you will get an error, this error's stack trace depends actually on the js engine:

  • Cannot read property of null in Chrome
  • null is not an object in Safari

UPDATE: The real issue in fact was why IOS's error wasn't well built on Rollbar, as it was suggested, I join what OP added in comments:

the greatest difference is that for Chrome the error is split on each line (stack trace) with each line starting with "at .... " with the file at the end (e.g main.js) but for iOS the error goes on one line with "step@" instead of "at" as if it is minified

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, but the greatest difference is that for Chrome the error is split on each line (stack trace) with each line starting with "at .... " with the file at the end (e.g main.js) but for iOS the error goes on one line with "step@" instead of "at" as if it is minified. I think should add this to the description.
@D.Ragoo I think the question should be refactored then, since I did not get your real issue. I thought you were asking for why do we have two different stack traces, however your problem is that why it wasn't well built on Rollbar.
0

The error was thrown from an async method. Thus Angular's ErrorHandler catches error thrown from non awaited async methods and returns the error as a Promise.

async foo() {
 const a = null;
 a.top();
}

foo(); // no await

Angular ErrorHandler Doc

Therefore in the handleError() method, add the line below

   handleError() {
     if (error.promise && error.rejection) { error = error.rejection; }
     // handle your error
   }

Found this solution thanks to: Angular custom error handler not getting error type from promise

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.