[clang-tools-extra] [clang-doc] Refactor error handling to use ExitOnError (PR #141699)
Paul Kirth via cfe-commits
cfe-commits at lists.llvm.org
Thu May 29 09:27:40 PDT 2025
================
@@ -371,22 +368,15 @@ Example usage for a project using a compile commands database:
sortUsrToInfo(USRToInfo);
// Ensure the root output directory exists.
- if (std::error_code Err = llvm::sys::fs::create_directories(OutDirectory);
- Err != std::error_code()) {
- llvm::errs() << "Failed to create directory '" << OutDirectory << "'\n";
- return 1;
+ if (std::error_code Err = llvm::sys::fs::create_directories(OutDirectory)) {
+ ExitOnErr(llvm::createFileError(OutDirectory, Err));
}
// Run the generator.
llvm::outs() << "Generating docs...\n";
- if (auto Err =
- G->get()->generateDocs(OutDirectory, std::move(USRToInfo), CDCtx)) {
- llvm::errs() << toString(std::move(Err)) << "\n";
- return 1;
- }
-
+ ExitOnErr(G->generateDocs(OutDirectory, std::move(USRToInfo), CDCtx));
llvm::outs() << "Generating assets for docs...\n";
- Err = G->get()->createResources(CDCtx);
+ Err = G->createResources(CDCtx);
----------------
ilovepi wrote:
this seems unrelated. That said, should we just use `ExitOnError` here too? that seems better than printing a warning and then exiting. I don't recall why we don't return failure if an error happens creating resources ... for most backends that's a rather big deal.
If all the tests pass with this using `ExitOnError`, then lets do that, otherwise lets drop this bit, and add a TODO for us to figure out how to handle this case more gracefully.
https://github.com/llvm/llvm-project/pull/141699
More information about the cfe-commits
mailing list