From 145ea9698f5e3488e6c7cbd684e6637f09e56d6f Mon Sep 17 00:00:00 2001 From: Martin Tirion Date: Thu, 2 Nov 2023 17:16:12 +0100 Subject: [PATCH 1/2] Added exception handling of hard to trace error --- .../DocLinkChecker/Helpers/MarkdownHelper.cs | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/DocLinkChecker/DocLinkChecker/Helpers/MarkdownHelper.cs b/src/DocLinkChecker/DocLinkChecker/Helpers/MarkdownHelper.cs index 6182451..9dfdd16 100644 --- a/src/DocLinkChecker/DocLinkChecker/Helpers/MarkdownHelper.cs +++ b/src/DocLinkChecker/DocLinkChecker/Helpers/MarkdownHelper.cs @@ -1,6 +1,7 @@ namespace DocLinkChecker.Helpers { using System; + using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -220,17 +221,29 @@ private static (PipeTable table, List errors) private static (PipeTable table, List errors) ValidatePipeTableWithText(string markdownFilePath, string markdown, Table table) { - PipeTable pipeTable = new (markdownFilePath, table.Line, table.Column); + PipeTable pipeTable = null; + int start = 0; + int len = 0; + string line = string.Empty; List errors = new (); - int start = table.Span.Start; - while (start > 0 && markdown.Substring(start, 1) != "\n") + try { - start--; - } + pipeTable = new (markdownFilePath, table.Line, table.Column); + + start = Math.Max(table.Span.Start, 0); + while (start > 0 && markdown.Substring(start, 1) != "\n") + { + start--; + } - int len = markdown.IndexOf('\r', start) - start; - string line = markdown.Substring(start, len); + len = markdown.IndexOf('\r', start) - start; + line = markdown.Substring(start, len); + } + catch (Exception ex) + { + Console.WriteLine($"PipeTable error {ex.Message}.\nfilepath: {markdownFilePath}\nmarkdown: {markdown.Substring(0, 40)}...\nTable: line={table.Line} col={table.Column} start={table.Span.Start}"); + } int row = 0; int nrCols = -1; From 1d1474ceed1a7ab649f7df1a7213fca6c2a017ed Mon Sep 17 00:00:00 2001 From: Martin Tirion Date: Thu, 2 Nov 2023 17:19:36 +0100 Subject: [PATCH 2/2] Fixed resource validation output (wrong path fixed) --- .../DocLinkChecker/Services/ResourceValidatorService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DocLinkChecker/DocLinkChecker/Services/ResourceValidatorService.cs b/src/DocLinkChecker/DocLinkChecker/Services/ResourceValidatorService.cs index a1971db..5c6413e 100644 --- a/src/DocLinkChecker/DocLinkChecker/Services/ResourceValidatorService.cs +++ b/src/DocLinkChecker/DocLinkChecker/Services/ResourceValidatorService.cs @@ -71,7 +71,7 @@ public ResourceValidatorService( orphanedResources.Add(resourceFullPath); errors.Add( new MarkdownError( - _fileService.GetRelativePath(resourceFullPath, _config.DocumentationFiles.SourceFolder), + _fileService.GetRelativePath(_config.DocumentationFiles.SourceFolder, resourceFullPath), 0, 0, MarkdownErrorSeverity.Error,