smalot / smalot/pdfparser

Usage of the "@" character in the code - error suppression

Open
#129 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Long story short, one of the PDF files I'm trying to parse throws an error - it basically cannot be parsed. Thing is that I cannot catch it with the standard try-catch block, because the parseFile() method from your package suppresses any errors thrown while parsing:

public function parseFile($filename)
{
    $content = file_get_contents($filename);
    return @$this->parseContent($content);
}

And the line in the Parser.php file: https://github.com/smalot/pdfparser/blob/master/src/Smalot/PdfParser/Parser.php#L74

I would say remove the @. And I would do it everywhere else you might have used it. What do you think?

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 src/Smalot/PdfParser/Parser.php and inspect parseFile(), then search the project for other uses of PHP's @ error-suppression operator. Confirm the relevant parsing errors can propagate to the caller's try-catch handling without suppression.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.