[clang-tools-extra] [clang-doc] Refactor error handling to use ExitOnError (PR #141699)

Paul Kirth via cfe-commits cfe-commits at lists.llvm.org
Fri May 30 10:15:28 PDT 2025


================
@@ -245,10 +247,32 @@ sortUsrToInfo(llvm::StringMap<std::unique_ptr<doc::Info>> &USRToInfo) {
   }
 }
 
+llvm::Error handleMappingPhaseErrors(llvm::Error Err,
+                                     bool IgnoreMappingFailures) {
+  if (!Err)
+    return llvm::Error::success();
+  if (IgnoreMappingFailures) {
+    llvm::errs() << "Error mapping decls in files. Clang-doc will ignore these "
+                    "files and continue:\n"
+                 << toString(std::move(Err)) << "\n";
+    return llvm::Error::success();
+  }
+  return Err;
+}
+
+llvm::Error ensureOutputDirExists(const std::string &OutDirectory) {
+  if (std::error_code Err = llvm::sys::fs::create_directories(OutDirectory)) {
+    return llvm::createFileError(OutDirectory, Err);
+  }
+  return llvm::Error::success();
+}
----------------
ilovepi wrote:

Looking at this, lets tweak this slightly. First, lets just call this `createDirectories()`, since its just wrapping the original call and wrapping it in an llvm::Error.  Next, the parameter should be StringRef. The braces on the if conflict w/ the style guide. My personal preference is to keep them, but project rules and all https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements

Lastly, I wonder if this should be an API in `support` with the rest of the file utilities. At the least

https://github.com/llvm/llvm-project/pull/141699


More information about the cfe-commits mailing list