Skip to content

Try...Suppress #4719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Try...Suppress #4719

wants to merge 1 commit into from

Conversation

MGatner
Copy link
Member

@MGatner MGatner commented May 21, 2021

Description
The @ suppression was preventing errors from being thrown & caught in the try...catch block, causing delete_files() to return true even when it failed. The "failure" test was still passing because RecursiveIteratorIterator still failed on the non-existent directory.

@samsonasik Is there a Rector rule for @ suppression in try...catch? Seems like it should be an easy one.

Checklist:

  • Securely signed commits
  • Component(s) with PHPdocs
  • Unit testing, with >80% coverage
  • n/a User guide updated
  • Conforms to style guide

@samsonasik
Copy link
Member

samsonasik commented May 22, 2021

Do you mean a rector rule that can remove @ error suppress? It seems not yet as far as I know.

There is ErrorSuppress node for that that we can use on create custom rector rule for it, like this:

Screen Shot 2021-05-22 at 09 00 27

@MGatner do you want me to create PR for it to add custom rector rule to https://github.com/codeigniter4/CodeIgniter4/tree/develop/utils/Rector for it?

@MGatner
Copy link
Member Author

MGatner commented May 22, 2021

In my opinion, there should never be an error suppression (e.g. @unlink($file)) inside a try {} block, because it prevents the error from being thrown and caught. I assume any instance of these would be a logic error.

If that's easy to write it would be a nice addition, but don't spend a lot of time on it. I thought there might be something already since this seems like perhaps not an uncommon mistake.

@@ -103,7 +103,7 @@ function directory_mirror(string $originDir, string $targetDir, bool $overwrite

$dirLen = strlen($originDir);

/** @var SplFileInfo $file */
// @var SplFileInfo $file
Copy link
Member

Choose a reason for hiding this comment

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

I don't think it is correct to change to simple comment. IDEs will not be able to parse the docblock

@paulbalandan
Copy link
Member

I agree. The @ operator should not be present inside a try catch as that would be contradicting.

As there is an ErrorSuppress node, maybe there's an equivalent Node object for try catch in the php-parser library. We should check the presence of both node types before applying the rector rule.

@samsonasik
Copy link
Member

Ok, so it should be RemoveErrorSuppressInsideTryRector

@samsonasik
Copy link
Member

@MGatner @paulbalandan here the PR #4724

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.

3 participants