@@ -2446,26 +2446,31 @@ Target::GetScratchTypeSystemForLanguage(lldb::LanguageType language,
2446
2446
if (auto *new_swift_scratch_ctx =
2447
2447
llvm::dyn_cast_or_null<TypeSystemSwiftTypeRefForExpressions>(
2448
2448
type_system_or_err->get ())) {
2449
+ auto report_error = [&](std::string message) {
2450
+ m_cant_make_scratch_type_system[language] = true ;
2451
+ m_scratch_type_system_map.RemoveTypeSystemsForLanguage (language);
2452
+ type_system_or_err = llvm::make_error<llvm::StringError>(
2453
+ message, llvm::inconvertibleErrorCode ());
2454
+ };
2449
2455
auto *new_swift_ast_ctx =
2450
2456
new_swift_scratch_ctx->GetSwiftASTContext ();
2451
- if (!new_swift_ast_ctx || new_swift_ast_ctx->HasFatalErrors ()) {
2457
+ if (!new_swift_ast_ctx)
2458
+ report_error (" Failed to construct SwiftASTContextForExpressions" );
2459
+ else if (new_swift_ast_ctx->HasFatalErrors ()) {
2460
+ DiagnosticManager diag_mgr;
2461
+ new_swift_ast_ctx->PrintDiagnostics (diag_mgr);
2462
+ std::string error_diagnostics = diag_mgr.GetString ();
2452
2463
if (StreamSP error_stream_sp =
2453
2464
GetDebugger ().GetAsyncErrorStream ()) {
2454
2465
error_stream_sp->PutCString (
2455
2466
" Can't construct shared Swift state "
2456
2467
" for this process after repeated "
2457
2468
" attempts.\n " );
2458
2469
error_stream_sp->PutCString (" Giving up. Fatal errors:\n " );
2459
- DiagnosticManager diag_mgr;
2460
- new_swift_ast_ctx->PrintDiagnostics (diag_mgr);
2461
- error_stream_sp->PutCString (diag_mgr.GetString ().c_str ());
2470
+ error_stream_sp->PutCString (error_diagnostics.c_str ());
2462
2471
error_stream_sp->Flush ();
2463
2472
}
2464
-
2465
- m_cant_make_scratch_type_system[language] = true ;
2466
- m_scratch_type_system_map.RemoveTypeSystemsForLanguage (language);
2467
- type_system_or_err = llvm::make_error<llvm::StringError>(
2468
- " DIAF" , llvm::inconvertibleErrorCode ());
2473
+ report_error (error_diagnostics);
2469
2474
}
2470
2475
}
2471
2476
}
0 commit comments