Skip to content

Log WebView load errors when exporting a note to PDF#1037

Merged
Crustack merged 1 commit into
Crustack:mainfrom
jim-daf:pdf-print-error-logging
May 30, 2026
Merged

Log WebView load errors when exporting a note to PDF#1037
Crustack merged 1 commit into
Crustack:mainfrom
jim-daf:pdf-print-error-logging

Conversation

@jim-daf
Copy link
Copy Markdown
Contributor

@jim-daf jim-daf commented May 19, 2026

Closes #1036

What this does

Adds a single onReceivedError(view, errorCode, description, failingUrl) override to the WebViewClient used in Context.printPdf(...) in app/src/main/java/android/print/PdfExtensions.kt. It logs the error code, description and failing URL with Log.w. Adds a small file-level private const val TAG = "PdfExtensions".

No behaviour change in the happy path. No new dependencies.

Why

onPageFinished currently fires regardless of whether the load succeeded, so a print that ended up with missing assets ships through createPrintDocumentAdapter(...) and produces a half-rendered PDF with no logcat trace. This override makes the failure visible so future "exported PDF is missing parts" reports have something concrete to look at.

Note on the signature

I used the deprecated 4-arg form rather than the API 23+ (WebView, WebResourceRequest, WebResourceError) overload on purpose. The app's minSdk is 21 and the framework dispatches the deprecated form on every API level when nothing else is overridden, so this single override actually fires for every user. Happy to switch to the new signature gated on Build.VERSION.SDK_INT >= M if you would prefer that style.

Summary by CodeRabbit

  • Chores
    • Added error logging for PDF printing operations to capture detailed error information during failures.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 19, 2026

📝 Walkthrough

Walkthrough

PdfExtensions.kt adds logging to the WebView client used during PDF export. When WebView resource loading fails (e.g., unreachable images), an onReceivedError handler now logs the error code, description, and failing URL instead of silently continuing to print.

Changes

PDF WebView Error Logging

Layer / File(s) Summary
WebView error logging setup and handler
app/src/main/java/android/print/PdfExtensions.kt
Imports Log, defines a TAG constant, and adds an onReceivedError override to the WebViewClient that logs warnings with error code, description, and URL when resources fail to load during PDF rendering.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A rabbit hops through logs so clear,
Where WebView errors disappear no more!
From silent fails we now have light,
Each broken image logged to sight,
PDF exports made transparent and bright! 📄✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding error logging for WebView failures during PDF export.
Linked Issues check ✅ Passed The code changes fully implement the requirement from issue #1036: adding an onReceivedError override that logs error details to WebViewClient.
Out of Scope Changes check ✅ Passed All changes are directly related to the objective of logging WebView errors during PDF export; no unrelated modifications are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/src/main/java/android/print/PdfExtensions.kt`:
- Line 35: The Log.w call that logs "PDF WebView load error" currently includes
the raw failingUrl (in PdfExtensions.kt, the Log.w(TAG, "... $failingUrl")
line); change it to sanitize the URL before logging by parsing the failingUrl
with java.net.URI (or android.net.Uri) and logging only the host and path (or
scheme://host/path) while stripping query and fragment (or fallback to a
redacted placeholder if parsing fails), then use that sanitized string in the
Log.w message instead of the full failingUrl.
- Around line 28-36: The WebView error handler only overrides the deprecated
4-arg onReceivedError (main-frame only) so subresource failures on API 23+ are
missed; add the API‑23+ override onReceivedError(view: WebView?, request:
WebResourceRequest?, error: WebResourceError?) alongside the existing
onReceivedError(view: WebView?, errorCode: Int, description: String?,
failingUrl: String?) and route both to a shared logger method (e.g.,
logWebViewError(...) or a private logError function that accepts
code/description/url and uses TAG) so all errors (main-frame and subresource)
are logged; keep `@Suppress`("DEPRECATION") on the 4-arg override and use
request?.url?.toString() and error?.errorCode/error?.description where
appropriate to populate the shared logger.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 95a5ed7b-12a7-4257-9b99-ae7cc5ae1248

📥 Commits

Reviewing files that changed from the base of the PR and between cd2a7b6 and d17f28c.

📒 Files selected for processing (1)
  • app/src/main/java/android/print/PdfExtensions.kt

Comment thread app/src/main/java/android/print/PdfExtensions.kt
Comment thread app/src/main/java/android/print/PdfExtensions.kt
@Crustack
Copy link
Copy Markdown
Owner

LGTM, thanks :)

@Crustack Crustack merged commit 842c809 into Crustack:main May 30, 2026
1 check passed
@Crustack Crustack added v7.11.2 enhancement New feature or request labels May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request v7.11.2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PDF export WebView swallows load errors silently

2 participants