Skip to content

fix: don't crash on None page offset in add_page_offset_to_toc_json (#153) - #556

Open
cxx5208 wants to merge 1 commit into
VectifyAI:mainfrom
cxx5208:fix-toc-nonetype-addition-153
Open

cxx5208 wants to merge 1 commit into
VectifyAI:mainfrom
cxx5208:fix-toc-nonetype-addition-153

Conversation

@cxx5208

@cxx5208 cxx5208 commented Oct 7, 2026

Copy link
Copy Markdown

Fixes #153.

What was wrong

When the printed-page TOC and the extracted physical indices share no matching titles, calculate_page_offset() returns None (no reliable page→physical offset exists). add_page_offset_to_toc_json() then computed data[i]['page'] + offset — i.e. int + None — and crashed with:

TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'

Fix

In add_page_offset_to_toc_json() (pageindex/page_index_classic.py), return the items untouched when offset is None instead of crashing. This is safe because process_none_page_numbers(), which runs right after in process_toc_with_page_numbers(), is already designed to resolve physical indices for items that lack one.

Tests

  • Reproduced the exact TypeError from the issue before the fix with a minimal script (empty pairs → offset=None → crash).
  • Verified the fix resolves it and that the normal path (numeric offset) still computes physical_index correctly.
  • Added tests/test_issue_153.py with 5 regression tests (follows the existing test_issue_163.py convention).
  • Full suite: 237 passed; the 2 failures in test_page_index_md.py are pre-existing on the clean tree (missing optional deps), unrelated to this change.

calculate_page_offset() returns None when no reliable page->physical
offset can be computed (e.g. no title matches between the printed TOC
and the extracted physical indices). Passing that None into
add_page_offset_to_toc_json crashed with
TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'
(issue VectifyAI#153).

Leave items untouched when offset is None; process_none_page_numbers()
downstream already resolves physical indices for items that lack one.

Adds tests/test_issue_153.py regression tests.

Signed-off-by: Yeshvanth Raju Kurapati <76988460+cxx5208@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 7, 2026 20:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

No deployments
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.

Unsupported operand type(s) for +: 'int' and 'NoneType'

2 participants