@@ -388,7 +388,7 @@ namespace AppInstaller::CLI::Workflow
388
388
return authArgs;
389
389
}
390
390
391
- HRESULT HandleException (Execution::Context& context, std::exception_ptr exception )
391
+ HRESULT HandleException (Execution::Context* context, std::exception_ptr exception )
392
392
{
393
393
try
394
394
{
@@ -399,47 +399,67 @@ namespace AppInstaller::CLI::Workflow
399
399
{
400
400
// Even though they are logged at their source, log again here for completeness.
401
401
Logging::Telemetry ().LogException (Logging::FailureTypeEnum::ResultException, re.what ());
402
- context.Reporter .Error () <<
403
- Resource::String::UnexpectedErrorExecutingCommand << ' ' << std::endl <<
404
- GetUserPresentableMessage (re) << std::endl;
402
+ if (context)
403
+ {
404
+ context->Reporter .Error () <<
405
+ Resource::String::UnexpectedErrorExecutingCommand << ' ' << std::endl <<
406
+ GetUserPresentableMessage (re) << std::endl;
407
+ }
405
408
return re.GetErrorCode ();
406
409
}
407
410
catch (const winrt::hresult_error& hre)
408
411
{
409
412
std::string message = GetUserPresentableMessage (hre);
410
413
Logging::Telemetry ().LogException (Logging::FailureTypeEnum::WinrtHResultError, message);
411
- context.Reporter .Error () <<
412
- Resource::String::UnexpectedErrorExecutingCommand << ' ' << std::endl <<
413
- message << std::endl;
414
+ if (context)
415
+ {
416
+ context->Reporter .Error () <<
417
+ Resource::String::UnexpectedErrorExecutingCommand << ' ' << std::endl <<
418
+ message << std::endl;
419
+ }
414
420
return hre.code ();
415
421
}
416
422
catch (const Settings::GroupPolicyException& e)
417
423
{
418
- auto policy = Settings::TogglePolicy::GetPolicy (e.Policy ());
419
- auto policyNameId = policy.PolicyName ();
420
- context.Reporter .Error () << Resource::String::DisabledByGroupPolicy (policyNameId) << std::endl;
424
+ if (context)
425
+ {
426
+ auto policy = Settings::TogglePolicy::GetPolicy (e.Policy ());
427
+ auto policyNameId = policy.PolicyName ();
428
+ context->Reporter .Error () << Resource::String::DisabledByGroupPolicy (policyNameId) << std::endl;
429
+ }
421
430
return APPINSTALLER_CLI_ERROR_BLOCKED_BY_POLICY;
422
431
}
423
432
catch (const std::exception & e)
424
433
{
425
434
Logging::Telemetry ().LogException (Logging::FailureTypeEnum::StdException, e.what ());
426
- context.Reporter .Error () <<
427
- Resource::String::UnexpectedErrorExecutingCommand << ' ' << std::endl <<
428
- GetUserPresentableMessage (e) << std::endl;
435
+ if (context)
436
+ {
437
+ context->Reporter .Error () <<
438
+ Resource::String::UnexpectedErrorExecutingCommand << ' ' << std::endl <<
439
+ GetUserPresentableMessage (e) << std::endl;
440
+ }
429
441
return APPINSTALLER_CLI_ERROR_COMMAND_FAILED;
430
442
}
431
443
catch (...)
432
444
{
433
445
LOG_CAUGHT_EXCEPTION ();
434
446
Logging::Telemetry ().LogException (Logging::FailureTypeEnum::Unknown, {});
435
- context.Reporter .Error () <<
436
- Resource::String::UnexpectedErrorExecutingCommand << " ???" _liv << std::endl;
447
+ if (context)
448
+ {
449
+ context->Reporter .Error () <<
450
+ Resource::String::UnexpectedErrorExecutingCommand << " ???" _liv << std::endl;
451
+ }
437
452
return APPINSTALLER_CLI_ERROR_COMMAND_FAILED;
438
453
}
439
454
440
455
return E_UNEXPECTED;
441
456
}
442
457
458
+ HRESULT HandleException (Execution::Context& context, std::exception_ptr exception )
459
+ {
460
+ return HandleException (&context, exception );
461
+ }
462
+
443
463
void OpenSource::operator ()(Execution::Context& context) const
444
464
{
445
465
std::string_view sourceName;
0 commit comments