Fix unexpected end of JSON error

Summary:
This is the 6th most common error in our logging, and I just run into it after upgrading XCode. It happens when idb doesn't return any devices.

(because `''.split('\n')` results in `['']` not `[]`)

Reviewed By: jknoxville

Differential Revision: D25368759

fbshipit-source-id: 44b0e3a5dc4cf06ecdf2dff4a5692943e60d4b1d
This commit is contained in:
Michel Weststrate
2020-12-07 09:43:42 -08:00
committed by Facebook GitHub Bot
parent 698df77553
commit fa00575dec

View File

@@ -70,6 +70,7 @@ async function targets(idbPath: string): Promise<Array<DeviceTarget>> {
.trim() .trim()
.split('\n') .split('\n')
.map((line) => line.trim()) .map((line) => line.trim())
.filter(Boolean)
.map((line) => JSON.parse(line)) .map((line) => JSON.parse(line))
.filter(({type}: IdbTarget) => type !== 'simulator') .filter(({type}: IdbTarget) => type !== 'simulator')
.map((target: IdbTarget) => { .map((target: IdbTarget) => {
@@ -83,6 +84,7 @@ async function targets(idbPath: string): Promise<Array<DeviceTarget>> {
.toString() .toString()
.split('\n') .split('\n')
.map((line) => line.trim()) .map((line) => line.trim())
.filter(Boolean)
.map((line) => /(.+) \([^(]+\) \[(.*)\]( \(Simulator\))?/.exec(line)) .map((line) => /(.+) \([^(]+\) \[(.*)\]( \(Simulator\))?/.exec(line))
.filter(notNull) .filter(notNull)
.filter(([_match, _name, _udid, isSim]) => !isSim) .filter(([_match, _name, _udid, isSim]) => !isSim)