Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Get rid of error suppression #2210

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions library/Zend/Authentication/Adapter/Digest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace Zend\Authentication\Adapter;

use Zend\Authentication\Result as AuthenticationResult;
use Zend\Stdlib\ErrorHandler;

/**
* @category Zend
Expand Down Expand Up @@ -169,8 +170,11 @@ public function authenticate()
}
}

if (false === ($fileHandle = @fopen($this->filename, 'r'))) {
throw new Exception\UnexpectedValueException("Cannot open '$this->filename' for reading");
ErrorHandler::start(E_WARNING);
$fileHandle = fopen($this->filename, 'r');
$error = ErrorHandler::stop();
if (false === $fileHandle) {
throw new Exception\UnexpectedValueException("Cannot open '$this->filename' for reading", 0, $error);
}

$id = "$this->username:$this->realm";
Expand Down
8 changes: 6 additions & 2 deletions library/Zend/Authentication/Adapter/Http/FileResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

namespace Zend\Authentication\Adapter\Http;

use Zend\Stdlib\ErrorHandler;

/**
* HTTP Authentication File Resolver
*
Expand Down Expand Up @@ -102,9 +104,11 @@ public function resolve($username, $realm, $password = null)
}

// Open file, read through looking for matching credentials
$fp = @fopen($this->file, 'r');
ErrorHandler::start(E_WARNING);
$fp = fopen($this->file, 'r');
$error = ErrorHandler::stop();
if (!$fp) {
throw new Exception\RuntimeException('Unable to open password file: ' . $this->file);
throw new Exception\RuntimeException('Unable to open password file: ' . $this->file, 0, $error);
}

// No real validation is done on the contents of the password file. The
Expand Down
5 changes: 3 additions & 2 deletions library/Zend/Authentication/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
},
"target-dir": "Zend/Authentication",
"require": {
"php": ">=5.3.3"
"php": ">=5.3.3",
"zendframework/zend-stdlib": "self.version"
},
"suggest": {
"zendframework/zend-db": "Zend\\Db component",
"zendframework/zend-uri": "Zend\\Uri component",
"zendframework/zend-session": "Zend\\Session component"
}
}
}
27 changes: 17 additions & 10 deletions library/Zend/Cache/Pattern/CallbackCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Zend\Cache\Exception;
use Zend\Cache\StorageFactory;
use Zend\Stdlib\ErrorHandler;

/**
* @category Zend
Expand Down Expand Up @@ -145,19 +146,22 @@ protected function generateCallbackKey($callback, array $args)
$object = $callback[0];
}
if (isset($object)) {
ErrorHandler::start();
try {
$serializedObject = @serialize($object);
$serializedObject = serialize($object);
} catch (\Exception $e) {
ErrorHandler::stop();
throw new Exception\RuntimeException(
"Can't serialize callback: see previous exception", 0, $e
);
}
$error = ErrorHandler::stop();

if (!$serializedObject) {
$lastErr = error_get_last();
throw new Exception\RuntimeException(
"Can't serialize callback: " . $lastErr['message']
);
throw new Exception\RuntimeException(sprintf(
'Cannot serialize callback%s',
($error ? ': ' . $error->getMessage() : '')
), 0, $error);
}
$callbackKey.= $serializedObject;
}
Expand All @@ -178,19 +182,22 @@ protected function generateArgumentsKey(array $args)
return '';
}

ErrorHandler::start();
try {
$serializedArgs = @serialize(array_values($args));
$serializedArgs = serialize(array_values($args));
} catch (\Exception $e) {
ErrorHandler::stop();
throw new Exception\RuntimeException(
"Can't serialize arguments: see previous exception"
, 0, $e);
}
$error = ErrorHandler::stop();

if (!$serializedArgs) {
$lastErr = error_get_last();
throw new Exception\RuntimeException(
"Can't serialize arguments: " . $lastErr['message']
);
throw new Exception\RuntimeException(sprintf(
'Cannot serialize arguments%s',
($error ? ': ' . $error->getMessage() : '')
), 0, $error);
}

return md5($serializedArgs);
Expand Down
9 changes: 6 additions & 3 deletions library/Zend/Cache/Storage/Adapter/AdapterOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,13 @@ public function setKeyPattern($keyPattern)
if ($keyPattern !== '') {
ErrorHandler::start(E_WARNING);
$result = preg_match($keyPattern, '');
ErrorHandler::stop();
$error = ErrorHandler::stop();
if ($result === false) {
$err = error_get_last();
throw new Exception\InvalidArgumentException("Invalid pattern '{$keyPattern}': {$err['message']}");
throw new Exception\InvalidArgumentException(sprintf(
'Invalid pattern "%s"%s',
$keyPattern,
($error ? ': ' . $error->getMessage() : '')
), 0, $error);
}
}

Expand Down
31 changes: 24 additions & 7 deletions library/Zend/File/Transfer/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@

namespace Zend\File\Transfer\Adapter;

use ErrorException;
use Zend\File\Transfer;
use Zend\File\Transfer\Exception;
use Zend\Filter;
use Zend\Filter\Exception as FilterException;
use Zend\I18n\Translator\Translator;
use Zend\I18n\Translator\TranslatorAwareInterface;
use Zend\Stdlib\ErrorHandler;
use Zend\Validator;

/**
Expand Down Expand Up @@ -1161,14 +1163,21 @@ public function getFileSize($files = null)
protected function detectFileSize($value)
{
if (file_exists($value['name'])) {
$result = sprintf("%u", @filesize($value['name']));
$filename = $value['name'];
} elseif (file_exists($value['tmp_name'])) {
$result = sprintf("%u", @filesize($value['tmp_name']));
$filename = $value['tmp_name'];
} else {
return null;
}

return $result;
ErrorHandler::start();
$filesize = filesize($filename);
$return = ErrorHandler::stop();
if ($return instanceof ErrorException) {
$filesize = 0;
}

return sprintf("%u", $filesize);
}

/**
Expand Down Expand Up @@ -1219,11 +1228,15 @@ protected function detectMimeType($value)
if (class_exists('finfo', false)) {
$const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME;
if (!empty($value['options']['magicFile'])) {
$mime = @finfo_open($const, $value['options']['magicFile']);
ErrorHandler::start();
$mime = finfo_open($const, $value['options']['magicFile']);
ErrorHandler::stop();
}

if (empty($mime)) {
$mime = @finfo_open($const);
ErrorHandler::start();
$mime = finfo_open($const);
ErrorHandler::stop();
}

if (!empty($mime)) {
Expand Down Expand Up @@ -1357,13 +1370,17 @@ protected function isPathWriteable($path)
$tempFile = rtrim($path, "/\\");
$tempFile .= '/' . 'test.1';

$result = @file_put_contents($tempFile, 'TEST');
ErrorHandler::start();
$result = file_put_contents($tempFile, 'TEST');
ErrorHandler::stop();

if ($result == false) {
return false;
}

$result = @unlink($tempFile);
ErrorHandler::start();
$result = unlink($tempFile);
ErrorHandler::stop();

if ($result == false) {
return false;
Expand Down
5 changes: 3 additions & 2 deletions library/Zend/File/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
},
"target-dir": "Zend/File",
"require": {
"php": ">=5.3.3"
"php": ">=5.3.3",
"zendframework/zend-stdlib": "self.version"
},
"suggest": {
"zendframework/zend-filter": "Zend\\Filter component",
"zendframework/zend-loader": "Zend\\Loader component",
"zendframework/zend-i18n": "Zend\\I18n component",
"zendframework/zend-validator": "Zend\\Validator component"
}
}
}
8 changes: 5 additions & 3 deletions library/Zend/Filter/AbstractFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Traversable;
use Zend\Stdlib\ArrayUtils;
use Zend\Stdlib\ErrorHandler;

/**
* @category Zend
Expand Down Expand Up @@ -39,11 +40,12 @@ abstract class AbstractFilter implements FilterInterface
public static function hasPcreUnicodeSupport()
{
if (static::$hasPcreUnicodeSupport === null) {
if (defined('PREG_BAD_UTF8_OFFSET_ERROR') || @preg_match('/\pL/u', 'a') == 1) {
static::$hasPcreUnicodeSupport = false;
ErrorHandler::start();
if (defined('PREG_BAD_UTF8_OFFSET_ERROR') || preg_match('/\pL/u', 'a') == 1) {
static::$hasPcreUnicodeSupport = true;
} else {
static::$hasPcreUnicodeSupport = false;
}
ErrorHandler::stop();
}
return static::$hasPcreUnicodeSupport;
}
Expand Down
6 changes: 5 additions & 1 deletion library/Zend/Filter/RealPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

namespace Zend\Filter;

use Zend\Stdlib\ErrorHandler;

/**
* @category Zend
* @package Zend_Filter
Expand Down Expand Up @@ -78,7 +80,9 @@ public function filter($value)
return realpath($path);
}

$realpath = @realpath($path);
ErrorHandler::start();
$realpath = realpath($path);
ErrorHandler::stop();
if ($realpath) {
return $realpath;
}
Expand Down
19 changes: 14 additions & 5 deletions library/Zend/Http/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Traversable;
use Zend\Stdlib;
use Zend\Stdlib\ArrayUtils;
use Zend\Stdlib\ErrorHandler;
use Zend\Uri\Http;

/**
Expand Down Expand Up @@ -598,11 +599,14 @@ protected function openTempStream()
);
}

if (false === ($fp = @fopen($this->streamName, "w+b"))) {
ErrorHandler::start();
$fp = fopen($this->streamName, "w+b");
$error = ErrorHandler::stop();
if (false === $fp) {
if ($this->adapter instanceof Client\Adapter\AdapterInterface) {
$this->adapter->close();
}
throw new Exception\RuntimeException("Could not open temp file {$this->streamName}");
throw new Exception\RuntimeException("Could not open temp file {$this->streamName}", 0, $error);
}

return $fp;
Expand Down Expand Up @@ -926,8 +930,11 @@ public function send(Request $request = null)
public function setFileUpload($filename, $formname, $data = null, $ctype = null)
{
if ($data === null) {
if (($data = @file_get_contents($filename)) === false) {
throw new Exception\RuntimeException("Unable to read file '{$filename}' for upload");
ErrorHandler::start();
$data = file_get_contents($filename);
$error = ErrorHandler::stop();
if ($data === false) {
throw new Exception\RuntimeException("Unable to read file '{$filename}' for upload", 0, $error);
}
if (!$ctype) {
$ctype = $this->detectFileMimeType($filename);
Expand Down Expand Up @@ -1156,7 +1163,9 @@ protected function detectFileMimeType($file)
// First try with fileinfo functions
if (function_exists('finfo_open')) {
if (self::$fileInfoDb === null) {
self::$fileInfoDb = @finfo_open(FILEINFO_MIME);
ErrorHandler::start();
self::$fileInfoDb = finfo_open(FILEINFO_MIME);
ErrorHandler::stop();
}

if (self::$fileInfoDb) {
Expand Down
22 changes: 16 additions & 6 deletions library/Zend/Http/Client/Adapter/Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

use Zend\Http\Client;
use Zend\Http\Client\Adapter\Exception as AdapterException;
use Zend\Http\Response;
use Zend\Stdlib\ErrorHandler;

/**
* HTTP Proxy-supporting Zend_Http_Client adapter class, based on the default
Expand Down Expand Up @@ -154,8 +156,11 @@ public function write($method, $uri, $http_ver = '1.1', $headers = array(), $bod
}

// Send the request
if (! @fwrite($this->socket, $request)) {
throw new AdapterException\RuntimeException("Error writing request to proxy server");
ErrorHandler::start();
$test = fwrite($this->socket, $request);
$error = ErrorHandler::stop();
if (!$test) {
throw new AdapterException\RuntimeException("Error writing request to proxy server", 0, $error);
}

if (is_resource($body)) {
Expand Down Expand Up @@ -195,23 +200,28 @@ protected function connectHandshake($host, $port = 443, $http_ver = '1.1', array
$request .= "\r\n";

// Send the request
if (! @fwrite($this->socket, $request)) {
throw new AdapterException\RuntimeException("Error writing request to proxy server");
ErrorHandler::start();
$test = fwrite($this->socket, $request);
$error = ErrorHandler::stop();
if (!$test) {
throw new AdapterException\RuntimeException("Error writing request to proxy server", 0, $error);
}

// Read response headers only
$response = '';
$gotStatus = false;
while ($line = @fgets($this->socket)) {
ErrorHandler::start();
while ($line = fgets($this->socket)) {
$gotStatus = $gotStatus || (strpos($line, 'HTTP') !== false);
if ($gotStatus) {
$response .= $line;
if (!rtrim($line)) break;
}
}
ErrorHandler::stop();

// Check that the response from the proxy is 200
if (\Zend\Http\Response::extractCode($response) != 200) {
if (Response::extractCode($response) != 200) {
throw new AdapterException\RuntimeException("Unable to connect to HTTPS proxy. Server response: " . $response);
Copy link
Member

Choose a reason for hiding this comment

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

previous exception

}

Expand Down
Loading