Repository navigation
feat: reject ref and PdfDocument methods with coded PdfMethodErrors - #73
Merged
Merged
Conversation
The view's promise methods (getOutline, getPageSizes, renderPage, print, getFormFields, setFormFieldValues, exportDocument) and PdfDocument's reads rejected with plain Errors: no code to match on, messages that differed between platforms, and on Android the exception class and the whole stack trace in the message. They now reject with a PdfMethodError whose code (PdfMethodErrorCode) is the same on both platforms: not-loaded, closed, invalid-argument, not-supported, not-permitted, busy, io-error, invalid-pdf, out-of-memory or unknown. message is one sentence; nativeDescription keeps the platform's text. Nitro rejections carry only a message, so native code rejects with "[code] message" (PdfMethodFailure in Swift, PdfMethodException in Kotlin) and one JS function parses its first line, after Android's exception class (renamed in minified builds) and before the stack trace. Platform errors are coded by type: file system errors are io-error, OutOfMemoryError out-of-memory, parse failures invalid-pdf, and the outline and metadata of encrypted documents on Android not-supported. The Nitro specs are unchanged. The same failure has the same code: a single-choice list box given several options is invalid-argument on iOS too (it was "not supported on iOS"), and Android's renderPage width message no longer reads "4096.0". On iOS, a read or export still waiting for its queue when the view closes or its source changes rejects with closed, as on Android, instead of resolving with the old document's data. The example's event lines show code and message, and the e2e flows match codes instead of message regexes. Behavior change: on Android, error.message no longer holds the exception class and the stack trace (nativeDescription does). Apps that matched on message text should match on code. Closes #65
# Conflicts: # docs/api.md
jkasprzyk17
added a commit
to duquerson/react-native-better-pdf
that referenced
this pull request
Oct 21, 2026
Since gmi-software#73 the ref's promise methods reject with a PdfMethodError, and apps match on its code rather than the message.
5 of 8 tasks
jkasprzyk17
added a commit
that referenced
this pull request
Oct 21, 2026
* fix: handle null, undefined and malformed sources gracefully (#66) * fix: harden invalid source reporting * fix: clarify invalid source diagnostics * fix: keep overlay context when source is empty * docs: mark source as optional and nullable in api-design * docs: name the not-loaded code for an unmounted PdfView Since #73 the ref's promise methods reject with a PdfMethodError, and apps match on its code rather than the message. --------- Co-authored-by: caja_autoservicio <caja.prat@cademartori.cl> Co-authored-by: Jakub Kasprzyk <kasprzykjakub@proton.me>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #65.
What changes
The ref's promise methods (
getOutline,getPageSizes,renderPage,print,getFormFields,setFormFieldValues,exportDocument) andPdfDocument's reads now reject with aPdfMethodError:codeis aPdfMethodErrorCode, the same on both platforms:not-loaded,closed,invalid-argument,not-supported,not-permitted,busy,io-error,invalid-pdf,out-of-memory,unknown.messageis one sentence: no exception class, no stack trace.nativeDescriptionkeeps the platform's text (on Android with the stack trace).PdfMethodErrorCodeis a separate union, so apps that switch exhaustively overonError'sPdfErrorCodedon't break.docs/api.mdlists the codes and when each method rejects with them; the guides name the codes where they describe rejections.How
The issue's option 2: a coded message. The Nitro specs don't change.
[code] message: SwiftPdfMethodFailure, KotlinPdfMethodException.io-error,OutOfMemoryErrorisout-of-memory, parse failures areinvalid-pdf.toPdfMethodError. It reads the first line, after Android's exception class and before the stack trace. The library ships no ProGuard rules, so in minified release builds the class name is renamed, and the parser accepts any class name.unknown.A JS test checks that the Swift and Kotlin code lists match the TS union.
Same failure, same code
invalid-argumenton iOS too, as on Android. A multi-select list box given several options is stillnot-supportedon iOS.getOutlineandgetMetadatafor encrypted documents reject withnot-supported(newEncryptedPdfException), notinvalid-pdf.renderPagewidth message no longer reads4096.0.sourcechanges now rejects withclosed, as on Android. Before, it resolved with the old document's data. Calls already running finish on both platforms.Behavior change (release notes)
On Android,
error.messageno longer holds the exception class and the stack trace;nativeDescriptiondoes. Apps that matched on message text should match oncode.Testing
bun test, 124 tests): the parser (iOS-shaped, Android-shaped with a stack trace, a renamed class, no code, empty, not an Error),not-loadedbefore mount,closedafterclose(), native rejections → codes. Run red before the change.testDebugUnitTest, 299 tests):PdfMethodException's message format, including the first lineprintStackTracewrites (fbjni passes that text to JS), the code of each kind of platform failure, form value codes, andclosedfor work dropped on close.code: message. The flows assert codes instead of message regexes.viewer-sourcesasserts the full one-line message on both platforms.pdf-document,viewer-sources,viewer-forms,viewer-page-image,viewer-outline,viewer-page-sizesandstress-close-during-work, with no crashes.closedon iOS, by hand on both platforms:renderPagecalls at once), then tap "Swap" right away.closed: The document was closed.Not done: the agent skill in better-skills; it follows the release.
Need help on this PR? Tag
@codesmith-botwith what you need.