apache / apache/cordova-ios

Logger fails to print 'message' field of Error exception

Open
#809 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
2.2k
Forks
1k
Avg merge
12h 11m
Merged PRs (30d)
18

Description

# 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

Contributor guide

Open the contributing guide

Research direction

Start in CordovaLib/cordova.js at the exception-processing and logging paths around lines 1624, 1670, 1712, and 1726, then reproduce an uncaught Error on iOS. Trace the object formatting and verify that the resulting log includes the thrown Error's message, such as "setPosition: invalid or missing coordinates," without losing the existing error details.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
mobile-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.