Skip to content

Commit 2c41839

Browse files
authored
Improve error message when deleting a file locally to add redirects and update call sites (#1872)
* Improve error message when deleting a file locally to add redirects and update call sites * Emit as warning, its non breaking but we want folks to fix it
1 parent 4295de9 commit 2c41839

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5-
using System.Collections.Immutable;
65
using System.Diagnostics.CodeAnalysis;
76
using System.IO.Abstractions;
87
using System.Runtime.InteropServices;
@@ -248,9 +247,23 @@ private static void ValidateInternalUrl(InlineProcessor processor, string url, s
248247
if (string.IsNullOrWhiteSpace(url))
249248
return;
250249

250+
251251
var pathOnDisk = Path.GetFullPath(Path.Combine(includeFrom, url.TrimStart('/')));
252252
if (!context.Build.ReadFileSystem.File.Exists(pathOnDisk))
253-
processor.EmitError(link, $"`{url}` does not exist. resolved to `{pathOnDisk}");
253+
{
254+
if (context.Configuration.Redirects is not null && context.Configuration.Redirects.TryGetValue(url.TrimStart('/'), out var redirect))
255+
{
256+
var name = redirect.To ??
257+
(redirect.Many is not null
258+
? $"one of: {string.Join(", ", redirect.Many.Select(m => m.To))}"
259+
: "unknown"
260+
);
261+
processor.EmitWarning(link, $"Local file `{url}` has a redirect, please update this reference to: {name}");
262+
}
263+
else
264+
processor.EmitError(link, $"`{url}` does not exist. If it was recently removed add a redirect. resolved to `{pathOnDisk}");
265+
266+
}
254267
}
255268

256269
private static void ProcessLinkText(InlineProcessor processor, LinkInline link, MarkdownFile? markdown, string? anchor, string url, IFileInfo file)

0 commit comments

Comments
 (0)