Skip to content

Commit

Permalink
chore: Add error handling logics
Browse files Browse the repository at this point in the history
  • Loading branch information
filzrev committed May 22, 2024
1 parent 12ddaf6 commit bab0642
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/Docfx.Dotnet/DotnetApiCatalog.Compile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,19 @@ private static async Task<List<(IAssemblySymbol symbol, Compilation compilation)
});

using var workspace = MSBuildWorkspace.Create(msbuildProperties);
workspace.WorkspaceFailed += (sender, e) => Logger.LogWarning($"{e.Diagnostic}");
workspace.WorkspaceFailed += (sender, e) =>
{
var message = e.Diagnostic.ToString();
switch (e.Diagnostic.Kind)
{
case WorkspaceDiagnosticKind.Failure when !config.AllowCompilationErrors:
Logger.LogError(message);
break;
default:
Logger.LogWarning(message);
break;
}
};

if (files.TryGetValue(FileType.NotSupported, out var unsupportedFiles))
{
Expand Down
4 changes: 2 additions & 2 deletions src/docfx/Models/DefaultCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ public override int Execute(CommandContext context, Options options)
DotnetApiCatalog.Exec(config.metadata, new(), configDirectory).GetAwaiter().GetResult();
}
if (config.build is not null)
if (config.build is not null && !Logger.HasError)
{
BuildCommand.MergeOptionsToConfig(options, config.build, configDirectory);
serveDirectory = RunBuild.Exec(config.build, new(), configDirectory, outputFolder);
PdfBuilder.CreatePdf(serveDirectory).GetAwaiter().GetResult();
}
if (options.Serve && serveDirectory is not null)
if (options.Serve && serveDirectory is not null && !Logger.HasError)
{
RunServe.Exec(serveDirectory, options.Host, options.Port, options.OpenBrowser, options.OpenFile);
}
Expand Down

0 comments on commit bab0642

Please sign in to comment.