3
3
// See the LICENSE file in the project root for more information.
4
4
5
5
using System ;
6
+ using System . Diagnostics . CodeAnalysis ;
6
7
using System . IO ;
7
8
using System . Text ;
8
9
using System . Threading ;
@@ -159,24 +160,49 @@ private async Task<ExitCode> RunApp(ILogger logger, TestTargetOs target, Logs lo
159
160
return ExitCode . FAILED_TO_GET_BUNDLE_INFO ;
160
161
}
161
162
163
+ ExitCode exitCode = ExitCode . SUCCESS ;
164
+
162
165
if ( ! target . Platform . IsSimulator ( ) )
163
166
{
164
- var result = await InstallApp (
165
- appBundleInfo ,
166
- deviceName ,
167
- logger ,
168
- target ,
169
- logs ,
170
- mainLog ,
171
- cancellationToken ) ;
167
+ Exception ? installException = null ;
172
168
173
- if ( result != ExitCode . SUCCESS )
169
+ try
174
170
{
175
- return result ;
171
+ ( deviceName , exitCode ) = await InstallApp ( appBundleInfo , deviceName , logger , target , mainLog , cancellationToken ) ;
176
172
}
177
- }
173
+ catch ( Exception e )
174
+ {
175
+ installException = e ;
176
+ }
177
+
178
+ if ( exitCode != ExitCode . SUCCESS || installException != null )
179
+ {
180
+ var message = new StringBuilder ( ) . AppendLine ( "Application installation failed:" ) ;
181
+
182
+ if ( ErrorKnowledgeBase . IsKnownInstallIssue ( mainLog , out var failureMessage ) )
183
+ {
184
+ message . Append ( failureMessage . Value . HumanMessage ) ;
185
+ if ( failureMessage . Value . IssueLink != null )
186
+ {
187
+ message . AppendLine ( $ " Find more information at { failureMessage . Value . IssueLink } ") ;
188
+ }
189
+ }
190
+ else if ( installException != null )
191
+ {
192
+ message . AppendLine ( installException . ToString ( ) ) ;
193
+ }
194
+
195
+ logger . LogError ( message . ToString ( ) ) ;
178
196
179
- ExitCode exitCode ;
197
+ return exitCode ;
198
+ }
199
+
200
+ if ( string . IsNullOrEmpty ( deviceName ) )
201
+ {
202
+ logger . LogError ( "Failed to get the name of the device where application was installed!" ) ;
203
+ return ExitCode . PACKAGE_INSTALLATION_FAILURE ;
204
+ }
205
+ }
180
206
181
207
try
182
208
{
@@ -201,22 +227,24 @@ private async Task<ExitCode> RunApp(ILogger logger, TestTargetOs target, Logs lo
201
227
}
202
228
catch ( Exception e )
203
229
{
230
+ var message = new StringBuilder ( ) . AppendLine ( "Application run failed:" ) ;
231
+
204
232
if ( ErrorKnowledgeBase . IsKnownTestIssue ( mainLog , out var failureMessage ) )
205
233
{
206
- var msg = $ "Application run failed: { Environment . NewLine } { failureMessage . Value . HumanMessage } ." ;
234
+ message . Append ( failureMessage . Value . HumanMessage ) ;
207
235
if ( failureMessage . Value . IssueLink != null )
208
236
{
209
- msg += $ " Find more information at { failureMessage . Value . IssueLink } ";
237
+ message . AppendLine ( $ " Find more information at { failureMessage . Value . IssueLink } ") ;
210
238
}
211
-
212
- logger . LogError ( msg ) ;
213
239
}
214
240
else
215
241
{
216
- logger . LogError ( $ "Application run failed: { Environment . NewLine } { e } " ) ;
242
+ message . AppendLine ( e . ToString ( ) ) ;
217
243
}
218
244
219
- return ExitCode . APP_CRASH ;
245
+ logger . LogError ( message . ToString ( ) ) ;
246
+
247
+ exitCode = ExitCode . APP_LAUNCH_FAILURE ;
220
248
}
221
249
finally
222
250
{
@@ -236,12 +264,11 @@ private async Task<ExitCode> RunApp(ILogger logger, TestTargetOs target, Logs lo
236
264
return exitCode ;
237
265
}
238
266
239
- private async Task < ExitCode > InstallApp (
267
+ private async Task < ( string ? , ExitCode ) > InstallApp (
240
268
AppBundleInformation appBundleInfo ,
241
269
string ? deviceName ,
242
270
ILogger logger ,
243
271
TestTargetOs target ,
244
- Logs logs ,
245
272
IFileBackedLog mainLog ,
246
273
CancellationToken cancellationToken )
247
274
{
@@ -259,12 +286,12 @@ private async Task<ExitCode> InstallApp(
259
286
{
260
287
logger . LogError ( $ "Failed to find suitable device for target { target . AsString ( ) } " + Environment . NewLine +
261
288
"Please make sure the device is connected and unlocked." ) ;
262
- return ExitCode . DEVICE_NOT_FOUND ;
289
+ return ( null , ExitCode . DEVICE_NOT_FOUND ) ;
263
290
}
264
291
catch ( Exception e )
265
292
{
266
293
logger . LogError ( $ "Failed to install the app bundle:{ Environment . NewLine } { e } ") ;
267
- return ExitCode . PACKAGE_INSTALLATION_FAILURE ;
294
+ return ( null , ExitCode . PACKAGE_INSTALLATION_FAILURE ) ;
268
295
}
269
296
270
297
if ( ! result . Succeeded )
@@ -286,15 +313,20 @@ private async Task<ExitCode> InstallApp(
286
313
logger . LogError ( $ "Failed to install the app bundle (exit code={ result . ExitCode } )") ;
287
314
}
288
315
289
- return ExitCode . PACKAGE_INSTALLATION_FAILURE ;
316
+ return ( deviceName , ExitCode . PACKAGE_INSTALLATION_FAILURE ) ;
290
317
}
291
318
292
319
logger . LogInformation ( $ "Application '{ appBundleInfo . AppName } ' was installed successfully on device '{ deviceName } '") ;
293
320
294
- return ExitCode . SUCCESS ;
321
+ return ( deviceName , ExitCode . SUCCESS ) ;
295
322
}
296
323
297
- private async Task UninstallApp ( AppBundleInformation appBundleInfo , string deviceName , ILogger logger , IFileBackedLog mainLog , CancellationToken cancellationToken )
324
+ private async Task UninstallApp (
325
+ AppBundleInformation appBundleInfo ,
326
+ string deviceName ,
327
+ ILogger logger ,
328
+ IFileBackedLog mainLog ,
329
+ CancellationToken cancellationToken )
298
330
{
299
331
logger . LogInformation ( $ "Uninstalling the application '{ appBundleInfo . AppName } ' from device '{ deviceName } '") ;
300
332
0 commit comments