Skip to content

Add detailed error logging for HTML/PDF generation failures#684

Merged
KrzysztofPajak merged 2 commits intodevelopfrom
copilot/add-error-logging-for-html-generation
Apr 29, 2026
Merged

Add detailed error logging for HTML/PDF generation failures#684
KrzysztofPajak merged 2 commits intodevelopfrom
copilot/add-error-logging-for-html-generation

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 29, 2026

When Razor view rendering or PDF generation fails, exceptions are swallowed with no context about what went wrong or what HTML was produced. This makes diagnosing template/data issues very difficult.

Changes

ViewRenderService

  • Injected ILogger<ViewRenderService>
  • Wrapped RenderAsync in try/catch; on failure logs the view path and any partial HTML already written to the buffer before re-throwing

HtmlToPdfService

  • Injected ILogger<HtmlToPdfService>
  • Wrapped Document.ParseDocument / SaveAsPDF in try/catch for both PrintOrdersToPdf and PrintPackagingSlipsToPdf; on failure logs the full HTML passed to Scryber before re-throwing
catch (Exception ex)
{
    _logger.LogError(ex, "Error generating PDF from order HTML. HTML content: {Html}", html);
    throw;
}

Note: Logging full HTML at Error level will include order/shipment data (names, addresses). This only fires on actual failures — consider truncating if that's a concern in your production log retention policy.

…rvice

Agent-Logs-Url: https://github.com/grandnode/grandnode2/sessions/53809890-623e-4f82-b022-b85ca5e43b88

Co-authored-by: KrzysztofPajak <16772986+KrzysztofPajak@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds structured error logging around Razor view rendering and Scryber PDF generation to improve diagnosability when HTML/PDF output generation fails.

Changes:

  • Injected ILogger<ViewRenderService> and logs view path + partial rendered HTML on RenderAsync failures.
  • Injected ILogger<HtmlToPdfService> and logs HTML payload when Document.ParseDocument / SaveAsPDF fails for order and shipment PDFs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/Web/Grand.Web.Common/ViewRender/ViewRenderService.cs Adds logger injection and logs partial HTML output when view rendering throws.
src/Business/Grand.Business.Common/Services/Pdf/HtmlToPdfService.cs Adds logger injection and logs HTML input when Scryber parse/PDF save throws (orders + shipments).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Web/Grand.Web.Common/ViewRender/ViewRenderService.cs Outdated
Comment thread src/Business/Grand.Business.Common/Services/Pdf/HtmlToPdfService.cs
Comment thread src/Business/Grand.Business.Common/Services/Pdf/HtmlToPdfService.cs
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
doc.SaveAsPDF(stream);
try
{
TextReader sr = new StringReader(html);
doc.SaveAsPDF(stream);
try
{
TextReader sr = new StringReader(html);
@KrzysztofPajak KrzysztofPajak merged commit 2f0c2da into develop Apr 29, 2026
6 checks passed
@KrzysztofPajak KrzysztofPajak deleted the copilot/add-error-logging-for-html-generation branch April 29, 2026 19:13
@KrzysztofPajak KrzysztofPajak restored the copilot/add-error-logging-for-html-generation branch April 29, 2026 19:14
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.

3 participants