Add error messages for Swift module map parser

Parser errors with large Swift module map files can be hard to diagnose.
Refactor the parser to return an llvm::Error so clearer diagnostics can
be passed to the user.
This commit is contained in:
Richard Howell
2025-09-05 13:26:07 -07:00
parent 61cb1a9126
commit 0b829bfab1
5 changed files with 114 additions and 25 deletions

View File

@@ -1604,8 +1604,12 @@ static bool generateReproducer(CompilerInstance &Instance,
}
auto map = llvm::json::parse(mapProxy->getData());
if (!map) {
diags.diagnose(SourceLoc(), diag::explicit_swift_module_map_corrupted,
mapOpts);
llvm::handleAllErrors(
map.takeError(), [&diags, &mapOpts](const llvm::json::ParseError &E) {
diags.diagnose(SourceLoc(),
diag::explicit_swift_module_map_corrupted, mapOpts,
E.message());
});
return true;
}
if (auto array = map->getAsArray()) {