Skip to content

Commit

Permalink
Remove error suppression in Regex HSL
Browse files Browse the repository at this point in the history
Reviewed By: fredemmott

Differential Revision: D16659539

fbshipit-source-id: 0a72c07ed9321665f9d0628ec2f3be3bdd58f19a
  • Loading branch information
hgoldstein authored and facebook-github-bot committed Aug 7, 2019
1 parent e6c902a commit 261d255
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
22 changes: 22 additions & 0 deletions src/private.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,25 @@ public function get(): Tr {
throw $this->exception;
}
}

/**
* Many PHP builtins emit warnings to stderr when they fail. This
* class allows us to squash warnings for a time without using PHP's
* `@` annotation.
*/
final class PHPWarningSuppressor implements \IDisposable {

private int $warningLevel;

public function __construct() {
/* HH_IGNORE_ERROR[2049] __PHPStdLib */
/* HH_IGNORE_ERROR[4107] __PHPStdLib */
$this->warningLevel = \error_reporting(0);
}

public function __dispose(): void {
/* HH_IGNORE_ERROR[2049] __PHPStdLib */
/* HH_IGNORE_ERROR[4107] __PHPStdLib */
\error_reporting($this->warningLevel);
}
}
3 changes: 2 additions & 1 deletion src/regex/private.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ function regex_match<T as Regex\Match>(
Regex\Pattern<T> $pattern,
int $offset = 0,
): ?(T, int) {
using new PHPWarningSuppressor();
$offset = validate_offset($offset, Str\length($haystack));
$match = darray[];
/* HH_IGNORE_ERROR[2049] __PHPStdLib */
/* HH_IGNORE_ERROR[4107] __PHPStdLib */
$status = @\preg_match(
$status = \preg_match(
/* HH_IGNORE_ERROR[4110] */ $pattern,
$haystack,
/* HH_FIXME[3080] References are being removed from Hack */
Expand Down
3 changes: 2 additions & 1 deletion src/regex/regex.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ function replace<T as Match>(
$haystack1 = Str\slice($haystack, 0, $offset);
$haystack2 = Str\slice($haystack, $offset);

using new _Private\PHPWarningSuppressor();
/* HH_IGNORE_ERROR[2049] __PHPStdLib */
/* HH_IGNORE_ERROR[4107] __PHPStdLib */
$haystack3 = @\preg_replace($pattern, $replacement, $haystack2);
$haystack3 = \preg_replace($pattern, $replacement, $haystack2);
if ($haystack3 === null) {
throw new Exception($pattern);
}
Expand Down

0 comments on commit 261d255

Please sign in to comment.