Skip to content

Commit ad4aee7

Browse files
Return meaningful error when no devices available
Summary: `react-native run-ios --device` should report 'No iOS devices connected.' in case when no devices attached. However due to logic bug when empty array is being treatened as a boolean value, cli reports odd message, saying `Could not find device with the name: "true".` Disconnect all iOS devices from developer machine and run `react-native run-ios --device` in any project - console message should state that there are no devices available. Closes facebook#15603 Differential Revision: D5686891 Pulled By: shergin fbshipit-source-id: 289461b6f920691ad39e940ecca6d85cf2a3573b
1 parent 743dc20 commit ad4aee7

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

local-cli/runIOS/runIOS.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ function runIOS(argv, config, args) {
4747
);
4848
if (args.device) {
4949
const selectedDevice = matchingDevice(devices, args.device);
50-
if (selectedDevice){
50+
if (selectedDevice) {
5151
return runOnDevice(selectedDevice, scheme, xcodeProject, args.configuration, args.packager);
5252
} else {
53-
if (devices){
53+
if (devices && devices.length > 0) {
5454
console.log('Could not find device with the name: "' + args.device + '".');
5555
console.log('Choose one of the following:');
5656
printFoundDevices(devices);
@@ -67,10 +67,10 @@ function runIOS(argv, config, args) {
6767

6868
function runOnDeviceByUdid(args, scheme, xcodeProject, devices) {
6969
const selectedDevice = matchingDeviceByUdid(devices, args.udid);
70-
if (selectedDevice){
70+
if (selectedDevice) {
7171
return runOnDevice(selectedDevice, scheme, xcodeProject, args.configuration, args.packager);
7272
} else {
73-
if (devices){
73+
if (devices && devices.length > 0) {
7474
console.log('Could not find device with the udid: "' + args.udid + '".');
7575
console.log('Choose one of the following:');
7676
printFoundDevices(devices);
@@ -80,7 +80,7 @@ function runOnDeviceByUdid(args, scheme, xcodeProject, devices) {
8080
}
8181
}
8282

83-
function runOnSimulator(xcodeProject, args, scheme){
83+
function runOnSimulator(xcodeProject, args, scheme) {
8484
return new Promise((resolve) => {
8585
try {
8686
var simulators = JSON.parse(
@@ -205,7 +205,7 @@ function formattedDeviceName(simulator) {
205205
return `${simulator.name} (${simulator.version})`;
206206
}
207207

208-
function printFoundDevices(devices){
208+
function printFoundDevices(devices) {
209209
for (let i = devices.length - 1; i >= 0; i--) {
210210
console.log(devices[i].name + ' Udid: ' + devices[i].udid);
211211
}

0 commit comments

Comments
 (0)