Skip to content

feat(comparer): add ComparisonLog infrastructure for graceful error handling#99

Merged
JSv4 merged 2 commits intomainfrom
feature/comparison-log-infrastructure
Jan 26, 2026
Merged

feat(comparer): add ComparisonLog infrastructure for graceful error handling#99
JSv4 merged 2 commits intomainfrom
feature/comparison-log-infrastructure

Conversation

@JSv4
Copy link
Copy Markdown
Owner

@JSv4 JSv4 commented Jan 26, 2026

Summary

  • Adds optional logging infrastructure to the document comparison engine
  • Enables graceful handling of document issues (like orphaned footnotes) without failing comparisons
  • Provides detailed log entries with codes, messages, and document locations for debugging
  • Adds new WASM bindings and TypeScript types for log-enabled comparison methods

Background

Some documents have structural issues (e.g., footnote references pointing to non-existent footnote definitions) that previously caused the comparison to fail with "Invalid document" exceptions. This PR allows users to opt-in to logging mode where these issues are captured and reported while the comparison continues.

Changes

New files:

  • Docxodus/ComparisonLog.cs - Core logging infrastructure classes

Modified files:

  • Docxodus/WmlComparer.cs - Added Log property to settings, updated methods to log warnings instead of throwing
  • wasm/DocxodusWasm/DocumentComparer.cs - Added CompareDocumentsWithLog and CompareDocumentsToHtmlWithLog methods
  • wasm/DocxodusWasm/JsonContext.cs - Added DTOs for log entries and responses
  • npm/src/types.ts - Added TypeScript types for log entries and responses
  • npm/src/index.ts - Added wrapper functions for log-enabled comparison

API

C# (.NET):

var log = new ComparisonLog();
var settings = new WmlComparerSettings { Log = log };
var result = WmlComparer.Compare(doc1, doc2, settings);

foreach (var warning in log.Warnings)
    Console.WriteLine($"{warning.Code}: {warning.Message}");

TypeScript/JavaScript:

const result = await compareDocumentsWithLog(original, modified, {
  authorName: "Reviewer"
});

if (result.success && result.hasWarnings) {
  console.log("Warnings:", result.log);
}

Test plan

  • All existing tests pass (1191 passed)
  • WASM build succeeds
  • TypeScript compiles without errors
  • Manual test with malformed document (orphaned footnotes) - comparison succeeds with warnings logged

JSv4 added 2 commits January 26, 2026 11:30
…andling

Add optional logging infrastructure to the document comparison engine that:
- Captures warnings about document issues without failing the comparison
- Handles orphaned footnote/endnote references gracefully when logging is enabled
- Provides detailed log entries with codes, messages, and document locations

New classes:
- ComparisonLog: Collects log entries during comparison
- ComparisonLogEntry: Individual entry with level, code, message, details, location
- ComparisonLogCodes: Well-known codes like ORPHANED_FOOTNOTE_REFERENCE

API changes:
- WmlComparerSettings.Log: Optional log collector (null = throw on errors, set = log and continue)
- CompareDocumentsWithLog: Returns document + log in JSON response
- CompareDocumentsToHtmlWithLog: Returns HTML + log in JSON response

TypeScript bindings:
- ComparisonLogEntry, CompareResultWithLog, CompareToHtmlResultWithLog types
- ComparisonLogLevel enum and ComparisonLogCodes constants
- compareDocumentsWithLog() and compareDocumentsToHtmlWithLog() functions

Also fixes CompareDocumentsToHtmlFull to properly pass detailThreshold and
caseInsensitive options (previously only used in DOCX output).
@JSv4 JSv4 merged commit 0a0b8c6 into main Jan 26, 2026
6 checks passed
@JSv4 JSv4 deleted the feature/comparison-log-infrastructure branch January 26, 2026 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant