Closed elonzh closed 7 months ago
Good point. I agree matching against the error string is unfortunate.
TBH, I never really thought much about programmatic use of exceptions or handling of error subtypes.
However, I think I'd not add an enum, but just ask callers to check against the constants from the raw API (in this case, FPDF_ERR_*
).
Do you have any more places other than document loading where this may be applicable? Because most pdfium APIs are sort of limited to error or success (i.e. no distinction of specific errors), where there isn't really any further use for the return code.
Do you have any more places other than document loading where this may be applicable?
No other error cases have been found yet for me.
Will become available when the v5 development work is finished.
Checklist
pypdfium2
fromPyPI
orGitHub/pypdfium2-team
.Description
For example
error_code
when available.An common user case is pypdfium2 will raise
PdfiumError
when document is encrypted and we didn't provide a password.Right now if we want to detect such exceptions, the only way is matching the error string which is inefficient and unstable.
Prefer solution:
Add a enum class for
ErrorToStr
and expose aerror_code
in PdfiumError`.Install Info
Validity