Skip to content

Commit 024bec1

Browse files
committed
Improve error logging if SwiftASTContext cannot be constructed
1 parent 95446f8 commit 024bec1

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

lldb/source/Target/Target.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2446,26 +2446,31 @@ Target::GetScratchTypeSystemForLanguage(lldb::LanguageType language,
24462446
if (auto *new_swift_scratch_ctx =
24472447
llvm::dyn_cast_or_null<TypeSystemSwiftTypeRefForExpressions>(
24482448
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+
};
24492455
auto *new_swift_ast_ctx =
24502456
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();
24522463
if (StreamSP error_stream_sp =
24532464
GetDebugger().GetAsyncErrorStream()) {
24542465
error_stream_sp->PutCString(
24552466
"Can't construct shared Swift state "
24562467
"for this process after repeated "
24572468
"attempts.\n");
24582469
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());
24622471
error_stream_sp->Flush();
24632472
}
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);
24692474
}
24702475
}
24712476
}

0 commit comments

Comments
 (0)