smalot / smalot/pdfparser

Why return an object ElementMissing instead of throwing an ElementMissingException?

Open
#431 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug question
Dominant language
PHP
Stars
2.7k
Forks
579
Avg merge
2m
Merged PRs (30d)
1

Description

I am debugging an "Missing encoding data for: """ and I noticed something that maybe is wrong...

Should Header->get($name) return an object of ElementMissing instead of throwing something like ElementMissingException?

   /**
     * @param string $name
     *
     * @return Element|PDFObject
     */
    public function get($name)
    {
        if (\array_key_exists($name, $this->elements)) {
            return $this->resolveXRef($name);
        }

        return new ElementMissing();
    }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Header->get($name) method and its ElementMissing return path, then trace the missing-encoding case described in the report. Compare the current behavior with the proposed exception-based contract; done requires a decided, documented behavior and confirmation that the affected lookup path handles missing elements consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend-api-design
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.