Skip to content

raise a ValueError for an internal link that add_link() did not create - #2059

Merged
andersonhc merged 1 commit into
py-pdf:masterfrom
RavSinghChandan:link-invalid-index-error
Oct 25, 2026
Merged

andersonhc merged 1 commit into
py-pdf:masterfrom
RavSinghChandan:link-invalid-index-error

Conversation

@RavSinghChandan

Copy link
Copy Markdown

FPDF.link() (used by cell(), multi_cell(), write() and image()) checked an integer link with an assert, so a link that add_link() did not return, such as cell(text="Page 1", link=999), raised a bare AssertionError, and with python -O the assert is removed and it became a KeyError. The neighbouring check for a link without a page number already raises a ValueError.

It now raises ValueError: Link with an invalid index: 999 (doc #links=0) - internal links must be created with add_link(). Added a test next to test_inserting_link_with_no_page_number.

@andersonhc
andersonhc merged commit 2f2138d into py-pdf:master Oct 25, 2026
23 checks passed
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.

2 participants