Logger fails to print 'message' field of Error exception
Bug Report
cordova.js on iOS seems unable to properly log a thrown exception of type Error
Problem
Found this in IndoorAtlas, but it could happen anywhere. IndoorAtlas correctly detects an error in a passed argument and throws an exception like this: https://github.com/IndoorAtlas/cordova-plugin/blob/5df032179d5237b26f25594e19f83f0541178a9d/www/IndoorAtlas.js#L516
if (!isNumber(position.latitude) || !isNumber(position.longitude))
throw new Error('setPosition: invalid or missing coordinates');
which throws an Error object like this:
{
column: 87,
line: 517,
message: "setPosition: invalid or missing coordinates",
sourceURL: "http://localhost:12101/plugins/cordova-plugin-indooratlas/www/IndoorAtlas.js",
stack: "http://localhost:12101/plugins/cordova-plugin-indooratlas/www/IndoorAtlas.js:517:8…"
}
What is expected to happen?
It should log the error in a manner that includes the meaningful message originally thrown as the error, i.e., "setPosition: invalid or missing coordinates"
What does actually happen?
The output to the log is actually this -- no mention of the 'message' field in the thrown object:
2020-03-17 16:06:29.575296-0400 Vium[45367:3592590] ERROR:
{"line":517,"column":87,"sourceURL":"http://localhost:12101/plugins/cordova-plugin-indooratlas/www/IndoorAtlas.js"}
Information
cordova.js, in processing the exception to log it, calls this: https://github.com/apache/cordova-ios/blob/d8f4b62d4da8eca8226de8bb79fbc91a949f9850/CordovaLib/cordova.js#L1624
Which calls this: https://github.com/apache/cordova-ios/blob/d8f4b62d4da8eca8226de8bb79fbc91a949f9850/CordovaLib/cordova.js#L1670
Which calls this: https://github.com/apache/cordova-ios/blob/d8f4b62d4da8eca8226de8bb79fbc91a949f9850/CordovaLib/cordova.js#L1712
Which, because the logging code has determined that "%o" is the format to apply to logging this object, calls this: https://github.com/apache/cordova-ios/blob/d8f4b62d4da8eca8226de8bb79fbc91a949f9850/CordovaLib/cordova.js#L1726
Something about the calling or behavior of the JSON.stringify() call returns "" instead of something correct, and the message gets lost.
Command or Code
It appears all you have to do is throw a new Error and have it make it uncaught through to cordova's logger.
Environment, Platform, Device
iOS. The lines above are taken from cordova.js.
Version information
Checklist
- [x] I searched for existing GitHub issues
- [x] I updated all Cordova tooling to most recent version for Meteor
- [x] I included all the necessary information above