Skip to content

--level 0 / negative --level silently produces a misleading "no usable outline" error instead of being rejected #5

Description

@adisakshya

Context

split_book.py, main() / build_arg_parser(). Compare to --fixed/--target-pages, which are already validated as positive integers with a clear error message.

Problem

--level has no validation. Internally, _walk_outline starts depth counting at 1, so --level 0 or any negative value can never match any outline entry — it silently falls through to the generic "no usable outline found at --level N" error, even on a PDF that has a perfectly good outline.

Reproduction

  1. Use any PDF with a normal, working outline at level 1.
  2. python split_book.py book.pdf --level 0 --list
  3. Output: Error: no usable outline found at --level 0. Try a different --level (e.g. --level 1), ... — despite the outline existing and being perfectly usable at level 1. Confirmed.

Expected

--level should be validated as a positive integer up front (same pattern already used for --fixed/--target-pages in main()), with a message like: Error: --level must be a positive integer, got 0.

Actual

No validation; produces a confusing generic "no outline found" message instead.

Acceptance criteria

  • --level 0 and negative --level values are rejected with a clear, specific error before any outline parsing is attempted.
  • Regression test(s) added, mirroring the existing --fixed/--target-pages validation tests.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions