4343using namespace clang ::ast_matchers;
4444using namespace clang ::tooling;
4545using namespace clang ;
46+ static llvm::ExitOnError ExitOnErr;
4647
4748static llvm::cl::extrahelp CommonHelp (CommonOptionsParser::HelpMessage);
4849static llvm::cl::OptionCategory ClangDocCategory (" clang-doc options" );
@@ -249,6 +250,8 @@ int main(int argc, const char **argv) {
249250 llvm::sys::PrintStackTraceOnErrorSignal (argv[0 ]);
250251 std::error_code OK;
251252
253+ ExitOnErr.setBanner (" clang-doc error: " );
254+
252255 const char *Overview =
253256 R"( Generates documentation from source code and comments.
254257
@@ -272,11 +275,7 @@ Example usage for a project using a compile commands database:
272275 // Fail early if an invalid format was provided.
273276 std::string Format = getFormatString ();
274277 llvm::outs () << " Emiting docs in " << Format << " format.\n " ;
275- auto G = doc::findGeneratorByName (Format);
276- if (!G) {
277- llvm::errs () << toString (G.takeError ()) << " \n " ;
278- return 1 ;
279- }
278+ auto G = ExitOnErr (doc::findGeneratorByName (Format));
280279
281280 ArgumentsAdjuster ArgAdjuster;
282281 if (!DoxygenOnly)
@@ -297,10 +296,7 @@ Example usage for a project using a compile commands database:
297296 {UserStylesheets.begin (), UserStylesheets.end ()}};
298297
299298 if (Format == " html" ) {
300- if (auto Err = getHtmlAssetFiles (argv[0 ], CDCtx)) {
301- llvm::errs () << toString (std::move (Err)) << " \n " ;
302- return 1 ;
303- }
299+ ExitOnErr (getHtmlAssetFiles (argv[0 ], CDCtx));
304300 }
305301
306302 if (Format == " mustache" ) {
@@ -320,7 +316,7 @@ Example usage for a project using a compile commands database:
320316 " these files and continue:\n "
321317 << toString (std::move (Err)) << " \n " ;
322318 else {
323- llvm::errs () << toString ( std::move (Err)) << " \n " ;
319+ ExitOnErr ( std::move (Err));
324320 return 1 ;
325321 }
326322 }
@@ -391,22 +387,14 @@ Example usage for a project using a compile commands database:
391387 sortUsrToInfo (USRToInfo);
392388
393389 // Ensure the root output directory exists.
394- if (std::error_code Err = llvm::sys::fs::create_directories (OutDirectory);
395- Err != std::error_code ()) {
396- llvm::errs () << " Failed to create directory '" << OutDirectory << " '\n " ;
397- return 1 ;
398- }
390+ ExitOnErr (
391+ llvm::errorCodeToError (llvm::sys::fs::create_directories (OutDirectory)));
399392
400393 // Run the generator.
401394 llvm::outs () << " Generating docs...\n " ;
402- if (auto Err =
403- G->get ()->generateDocs (OutDirectory, std::move (USRToInfo), CDCtx)) {
404- llvm::errs () << toString (std::move (Err)) << " \n " ;
405- return 1 ;
406- }
407-
395+ ExitOnErr (G->generateDocs (OutDirectory, std::move (USRToInfo), CDCtx));
408396 llvm::outs () << " Generating assets for docs...\n " ;
409- Err = G->get ()-> createResources (CDCtx);
397+ Err = G->createResources (CDCtx);
410398 if (Err) {
411399 llvm::outs () << " warning: " << toString (std::move (Err)) << " \n " ;
412400 }
0 commit comments