Repository navigation
Pilot C# 15 union and closed on LinkResolution - #4179
Conversation
There was a problem hiding this comment.
Requesting changes: this introduces regressions when cross-link resolution is intentionally unavailable (notably skip-cross-links/no-op resolver paths).
What is this? | From workflow: PR Review
Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not.
| link.SetData("isCrossLink", false); | ||
| } | ||
| else | ||
| processor.EmitError(link, resolution.ToDiagnosticMessage(uri)); |
There was a problem hiding this comment.
[HIGH] skipCrossLinks mode now hard-fails ordinary cross-links
This branch emits an error whenever ResolvedUri() is null, but NoopCrossLinkResolver intentionally returns LinkResolutionUnavailable (for --skip-cross-links fast validation). That means valid `(redacted) links now produce hard errors in the exact mode that is supposed to skip cross-link validation.
A concrete failure path is IsolatedBuildService with SkipCrossLinks=true, which wires NoopCrossLinkResolver.Instance; any parsed cross-link now hits this error path.
Please preserve the skip behavior by treating LinkResolutionUnavailable as a non-error passthrough here, while still emitting diagnostics for true resolution failures (LinkNotInIndex, LinkAnchorNotFound, etc.).
| var resolvedUri = resolution.ResolvedUri(); | ||
| if (resolvedUri is null) | ||
| { | ||
| block.EmitError(resolution.ToDiagnosticMessage(uri)); |
There was a problem hiding this comment.
[HIGH] Cross-link directive validation now errors when resolver is intentionally unavailable
resolver.Resolve(uri) returning LinkResolutionUnavailable is an expected state when cross-link resolution is intentionally disabled (for example fast validation builds using NoopCrossLinkResolver). This new unconditional error turns that opt-out mode into hard failures for directive links using cross-link schemes.
Please handle LinkResolutionUnavailable as a skip/no-op outcome in this path, and keep emitting errors for actual resolution problems.
Mpdreamz
left a comment
There was a problem hiding this comment.
Fixed in 27a8e63 — added is LinkResolutionUnavailable early-return guards in DiagnosticLinkInlineParser, DirectiveLinkValidator, and DocumentationSetNavigation before the diagnostic path. All three sites now pass silently when the resolver is intentionally unavailable, and still emit errors for real resolution failures (LinkNotInIndex, LinkAnchorNotFound, etc.).
| if (context.CrossLinkResolver.TryResolve(s => processor.EmitError(link, s), uri, out var resolvedUri)) | ||
| var resolution = context.CrossLinkResolver.Resolve(uri); | ||
| if (resolution is LinkResolutionUnavailable) | ||
| return; |
There was a problem hiding this comment.
[LOW] Preserve empty-link-text diagnostics when cross-link resolution is disabled
This early return skips the empty-link-text check below, so in --skip-cross-links mode (where the resolver returns LinkResolutionUnavailable) markdown like `[]((index.md/redacted) no longer emits the existing "empty link text" error.
Before this change, unresolved/no-op resolution still allowed that structural validation to run; now the parser exits before reaching it. Please keep the LinkResolutionUnavailable fast path, but still run the empty-link-text diagnostic so skip mode only disables cross-link resolution/fetching, not this content-quality check.
Replace the `bool TryResolve(Action<string>, Uri, out Uri?)` interface with a `LinkResolution` union whose nine cases carry their own diagnostic payloads. The `Action<string> errorEmitter` side channel is deleted from five signatures; a `ResolvedUri()` extension method holds the single exhaustive switch so CS8509 enforces completeness in one place rather than scattered across every call site. Also fixes two call sites (`AssemblerBuilder`, `CodexBuildService`) that were discarding the bool and relying solely on the emitter lambda firing — they now properly handle failure. Adds `closed` to four intentionally-finite hierarchies: `DocumentationFile`, `RoleLeaf`, `AskAiEvent` (wire-safe — `closed` does not change serialization representation), and `TopNavRenderItem`. Updates CLAUDE.md with the union-first rule naming `TryGet` as the documented exception. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
NoopCrossLinkResolver returns LinkResolutionUnavailable, which is the intentional signal that cross-link resolution is disabled (--skip-cross-links, isolated builds, live-reload initial state). The three call sites that unconditionally emitted an error for any null ResolvedUri() were turning valid cross-links into hard failures in exactly the modes meant to skip validation. Guard each site with an early return on LinkResolutionUnavailable before reaching the diagnostic path. Real resolution failures (LinkNotInIndex, LinkAnchorNotFound, etc.) still emit errors as before. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Main added floating-section link resolution while the pilot was open. It now returns a LinkFloatingPageNotFound case with the same diagnostic text instead of reporting through an error callback, and the C# authoring and markdown tests call Resolve instead of TryResolve. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
27a8e63 to
198ff6c
Compare
| if (uri is null) | ||
| context.Collector.EmitError(context.ConfigurationPath.FullName, resolution.ToDiagnosticMessage(crossLinkUri)); |
There was a problem hiding this comment.
Severity: P3 (Low)
This error is filed against the codex configuration path, and it no longer includes the "An error occurred while resolving cross-link {path}" header that the old 3-arg EmitError added. Some ToDiagnosticMessage outputs don't identify the cross-link being resolved: for example, LinkAnchorNotFound gives only a lookup path and fragment without the scheme, and redirect failures such as LinkRedirectTargetMissing identify a target but not necessarily the source redirect key. If multiple redirect entries share a target/path, the operator may not be able to determine which entry failed. Preserve the old URI context in the diagnostic. AssemblerBuilder drops the same header.
Generated by Libra. Specialist: libra-complexity. React with 👍 or 👎 to give feedback on this comment.
| var path = ToTargetUrlPath((crossLinkUri.Host + '/' + crossLinkUri.AbsolutePath.TrimStart('/')).Trim('/')); | ||
| resolvedUri = uriResolver.Resolve(crossLinkUri, path); | ||
| return true; | ||
| var synthesizedUri = uriResolver.Resolve(crossLinkUri, path); | ||
| return new LinkSynthesized(synthesizedUri, crossLinkUri.Scheme); |
There was a problem hiding this comment.
Severity: P3 (Low)
Add resolver-level tests that assert the new result cases, especially LinkSynthesized versus LinkResolved and the synthesized repository payload. The migrated tests flatten results through ResolvedUri() and diagnostic strings, so returning LinkResolved here instead would leave them green and lose the verified-versus-synthesized distinction this API introduces.
Generated by Libra. React with 👍 or 👎 to give feedback on this comment.
Docs preview (local build)Handbook preview: https://docs-v3-preview.elastic.dev/elastic/docs-builder/pull/4179/ Sample changed pages: |
Introduces the
LinkResolutionunion replacing thebool TryResolve(Action<string>, Uri, out Uri?)interface, and annotates four intentionally-finite hierarchies withclosed. Call sites become exhaustive switches enforced by CS8509; the diagnostic side-channel is deleted entirely.Affects: Cross-link resolution (
Elastic.Documentation.Links), Markdown pipeline (Elastic.Markdown), code style guidance (AGENTS.md)Prompt summary: Plan and apply C# 15
unionandclosedto docs-builder, starting with the quietest project in the repo as a pilot. Demonstrate both features together, fix real defects, and update the coding guidelines to prefer unions over ad-hoc bool-plus-out patterns going forward.Why
ICrossLinkResolver.TryResolvecarries anAction<string> errorEmitterside channel through five method signatures solely because the return type can't carry why resolution failed. Ten distinct failure modes collapse into the samefalse+ emitter call, so callers can't distinguish a synthesised dev URL from a genuine success, and two call sites (AssemblerBuilder,CodexBuildService) discard the bool entirely and rely wholly on the lambda firing. Three of four real consumers immediately write an adapter lambda just to bridge the emitter into a local diagnostic sink.closedon the four annotated hierarchies (DocumentationFile,RoleLeaf,AskAiEvent,TopNavRenderItem) removes the implicit possibility of unknown subtypes appearing at a match site without compile-time error.What
LinkResolutionunion (new type)src/Elastic.Documentation.Links/CrossLinks/LinkResolution.csdeclares a ten-case union —LinkResolved,LinkSynthesized, and eight failure cases, includingLinkFloatingPageNotFoundfor main's floating sections — each carrying exactly the payload its diagnostic needs. AResolvedUri()extension method holds the single exhaustive switch, so CS8509 fires in one place if the union gains a new case. AToDiagnosticMessage()extension replaces the inline format strings that were previously injected via the emitter.ICrossLinkResolverinterface redesignedResolve(Uri) → LinkResolutionreplacesTryResolve(Action<string>, Uri, out Uri?). TheAction<string>parameter is deleted from five signatures.NoopCrossLinkResolverandStepCrossLinkResolver— byte-identical implementations in two assemblies — both collapse toreturn new LinkResolutionUnavailable().LinkSynthesizedmakes a synthesised development URL distinguishable from a realLinkResolvedfor the first time.Two silent discard sites fixed
AssemblerBuilder.csandCodexBuildService.cswere_ = linkResolver.TryResolve(…)— the bool discarded, correctness resting solely on the lambda. Both now match onLinkResolutionand emit an error whenResolvedUri()returns null.closedannotations (behaviour-neutral)DocumentationFile,RoleLeaf,AskAiEvent, andTopNavRenderItemgainclosed; the redundantabstractkeyword is removed from each. Wire format is unchanged —closeddoes not affect[JsonPolymorphic]serialization.Code-style rule updated
AGENTS.mdgains a Results bullet (a method with more than one outcome returns aunion) and a Sealed hierarchies bullet (closed).TryGetX(key, out value)remains the documented exception for genuine keyed lookups where the out parameter carries no error information.Verify
Out of scope:
Elastic.Changelog— highest union density in the repo but 301 file-touches in eight weeks; items are parked in the plan backlog until that area settles.🤖 Generated with Claude Code