Skip to content

Debug fixes when CLI is used as a library#3113

Merged
rosen-vladimirov merged 4 commits into
masterfrom
vladimirov/debug-fixes
Sep 8, 2017
Merged

Debug fixes when CLI is used as a library#3113
rosen-vladimirov merged 4 commits into
masterfrom
vladimirov/debug-fixes

Conversation

@rosen-vladimirov

Copy link
Copy Markdown
Contributor

Fix UnhandledRejection error when failed to start application on iOS during debug

In case we are unable to start application on iOS device just before attaching a debugger, CLI will raise unhandled rejection. The problem is that we want to start two actions in parallel - start of application and attaching a debugger. We do not await the start application and when an error is raised in it, Unhandled Rejection is raised. In order to prevent this, use Promise.all - this way in case any of the operations fail, we'll receive it as error in the same method.

Fix attaching multiple times on deviceLost event

In LiveSync service we attach to deviceLost event in order to stop LiveSync operation in case device is detached. However we are attaching it on every change, so at some point CLI prints warning: Warning: Possible EventEmitter memory leak detected. 11 deviceLost listeners added. Use emitter.setMaxListeners() to increase limit Fix this by attaching only once.

Fix application is not started on iOS Simulator every other time

In case you are using iOS Simulator with version < 10, every second LiveSync operation does not start the app on device. The problem is that calling simctl terminate is not killing the app immediately. However the action is executed, so we call start application. After its been called, the terminate succeeds and kills the app. So the app is not running. When a change is applied we detect app is not running and just start it. So it works. Next change calls terminate and again the app seems like it has not been started. The fix is in ios-sim-portable, so update its version.

Fix executing of deploy/start app on device, which is not passed to the method

In PlatformService we create a canExecute method that does not work correctly in cases when CLI is used as a library. The problem is that in this case methods like deployPlatform and startApplication receive the device on which to execute the action through their arguments. However, the canExecute method relies on the devicesService.getDeviceByDeviceOption() method, which works with the $options.device. The last is never set in cases when CLI is used as a library. So the canExecute is changed and now it will work only in case it receives deviceIdentifier as argument. This requires changes in startApplication and deployPlatform methods, so they will send the deviceIdentifier to canExecute method.

…during debug

In case we are unable to start application on iOS device just before attaching a debugger, CLI will raise unhandled rejection.
The problem is that we want to start two actions in parallel - start of application and attaching a debugger.
We do not await the start application and when an error is raised in it, Unhandled Rejection is raised.
In order to prevent this, use Promise.all - this way in case any of the operations fail, we'll receive it as error in the same method.
In LiveSync service we attach to deviceLost event in order to stop LiveSync operation in case device is detached. However we are attaching it on every change, so at some point CLI prints warning:
`Warning: Possible EventEmitter memory leak detected. 11 deviceLost listeners added. Use emitter.setMaxListeners() to increase limit `

Fix this by attaching only once.
In case you are using iOS Simulator with version < 10, every second LiveSync operation does not start the app on device. The problem is that calling `simctl terminate` is not killing the app immediately.
However the action is executed, so we call start application. After its been called, the terminate succeeds and kills the app. So the app is not running. When a change is applied we detect app is not running and just start it.
So it works. Next change calls terminate and again the app seems like it has not been started.

The fix is in ios-sim-portable, so update its version.
…he method

In PlatformService we create a canExecute method that does not work correctly in cases when CLI is used as a library. The problem is that in this case methods like `deployPlatform` and `startApplication` receive the device on which to execute the action through their arguments. However, the canExecute method relies on the `devicesService.getDeviceByDeviceOption()` method, which works with the `$options.device`. The last is never set in cases when CLI is used as a library. So the canExecute is changed and now it will work only in case it receives deviceIdentifier as argument. This requires changes in `startApplication` and `deployPlatform` methods, so they will send the deviceIdentifier to canExecute method.

@Mitko-Kerezov Mitko-Kerezov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks all right to me

@rosen-vladimirov
rosen-vladimirov merged commit 0579ec7 into master Sep 8, 2017
@rosen-vladimirov
rosen-vladimirov deleted the vladimirov/debug-fixes branch September 8, 2017 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants