diff --git a/ApiDocs.Console/Program.cs b/ApiDocs.Console/Program.cs index a75ad81..7c213ee 100644 --- a/ApiDocs.Console/Program.cs +++ b/ApiDocs.Console/Program.cs @@ -101,7 +101,15 @@ static void Main(string[] args) FancyConsole.LogFileName = verbOptions.LogFile; var task = Task.Run(() => RunInvokedMethodAsync(options, verbName, verbOptions)); - task.Wait(); + try + { + task.Wait(); + } + catch (Exception ex) + { + FancyConsole.WriteLine(FancyConsole.ConsoleErrorColor, "Uncaught exception is causing a crash: {0}", ex); + Exit(failure: true, customExitCode: 40); + } } public static void LoadCurrentConfiguration(DocSetOptions options) @@ -204,7 +212,17 @@ private static void PrintAboutMessage() private static async Task GetDocSetAsync(DocSetOptions options) { FancyConsole.VerboseWriteLine("Opening documentation from {0}", options.DocumentationSetPath); - DocSet set = new DocSet(options.DocumentationSetPath); + DocSet set = null; + try + { + set = new DocSet(options.DocumentationSetPath); + } + catch (System.IO.FileNotFoundException ex) + { + FancyConsole.WriteLine(FancyConsole.ConsoleErrorColor, ex.Message); + Exit(failure: true); + return null; + } FancyConsole.VerboseWriteLine("Scanning documentation files..."); ValidationError[] loadErrors; @@ -964,9 +982,13 @@ private static void ConfigureAdditionalHeadersForAccount(CheckServiceOptions opt } } - private static void Exit(bool failure) + private static void Exit(bool failure, int? customExitCode = null) { - var exitCode = failure ? ExitCodeFailure : ExitCodeSuccess; + int exitCode = failure ? ExitCodeFailure : ExitCodeSuccess; + if (customExitCode.HasValue) + { + exitCode = customExitCode.Value; + } #if DEBUG Console.WriteLine("Exit code: " + exitCode); if (Debugger.IsAttached) diff --git a/ApiDocs.Validation/DocSet.cs b/ApiDocs.Validation/DocSet.cs index fd44ee2..66117a7 100644 --- a/ApiDocs.Validation/DocSet.cs +++ b/ApiDocs.Validation/DocSet.cs @@ -178,6 +178,9 @@ public static T[] TryLoadConfigurationFiles(string path) where T : ConfigFile List validConfigurationFiles = new List(); DirectoryInfo docSetDir = new DirectoryInfo(path); + if (!docSetDir.Exists) + return new T[0]; + var jsonFiles = docSetDir.GetFiles("*.json", SearchOption.AllDirectories); foreach (var file in jsonFiles) {