Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
336 views
in Technique[技术] by (71.8m points)

javascript - Ionic Angular error log differs between Android & iOS ( Cordova ) and cannot build stack trace on Rollbar for iOS

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...