Skip to content

Commit

Permalink
Deprecate remaining exceptions in \OpenSearch\Common\Exceptions and r…
Browse files Browse the repository at this point in the history
…eplace with new ones (#274)

* Deprecate remaining exceptions

Signed-off-by: Kim Pepper <[email protected]>

* Generate API

Signed-off-by: Kim Pepper <[email protected]>

---------

Signed-off-by: Kim Pepper <[email protected]>
  • Loading branch information
kimpepper authored Feb 3, 2025
1 parent e9ebb86 commit 289a387
Show file tree
Hide file tree
Showing 221 changed files with 351 additions and 292 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Connections, Connection pools and Selectors are deprecated. Use a PSR HTTP Client that supports retries instead.
- Throwing exceptions for different HTTP status codes is deprecated. Use the response object to check the status code instead.
- The following namespaces have been deprecated and will be removed in 3.0.0: 'async_search', 'searchable_snapshots', 'ssl', 'data_frame_transform_deprecated', 'monitoring'.
- A number of exceptions under `\OpenSearch\Common\Exceptions` are deprecated and moved to `\OpenSearch\Exception`.
### Removed
- Removed support for PHP 7.3, 7.4 and 8.0.
- Removed support for async requests which were never actually working.
### Fixed
- Fixed PHP 8.4 deprecations
- Fixed outdated tests
### Updated APIs
- Updated opensearch-php APIs to reflect [opensearch-api-specification@b9dcb25](https://github.com/opensearch-project/opensearch-api-specification/commit/b9dcb251d551e90ecfc416ba134efe83cbcbc1b3)
- Updated opensearch-php APIs to reflect [opensearch-api-specification@9df46f8](https://github.com/opensearch-project/opensearch-api-specification/commit/9df46f8134641ae5b429e3e9269858c7cb27e4f0)
- Updated opensearch-php APIs to reflect [opensearch-api-specification@592336a](https://github.com/opensearch-project/opensearch-api-specification/commit/592336afb88844f0c5785ba4b085dba3884ac580)
- Updated opensearch-php APIs to reflect [opensearch-api-specification@799d046](https://github.com/opensearch-project/opensearch-api-specification/commit/799d04622aeddce7b697665d63a29fc049e5088e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
*
* @deprecated in 2.4.0 and will be removed in 3.0.0.
*/
class BadMethodCallException extends \BadMethodCallException implements OpenSearchException
class BadMethodCallException extends \OpenSearch\Exception\BadMethodCallException
{
}
8 changes: 6 additions & 2 deletions src/OpenSearch/Common/Exceptions/RuntimeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@

namespace OpenSearch\Common\Exceptions;

use OpenSearch\Exception\OpenSearchExceptionInterface;
// @phpstan-ignore classConstant.deprecatedClass
@trigger_error(RuntimeException::class . ' is deprecated in 2.4.0 and will be removed in 3.0.0. Use \OpenSearch\Exception\RuntimeException instead.', E_USER_DEPRECATED);

class RuntimeException extends \RuntimeException implements OpenSearchExceptionInterface
/**
* @deprecated in 2.4.0 and will be removed in 3.0.0. Use \OpenSearch\Exception\RuntimeException instead.
*/
class RuntimeException extends \OpenSearch\Exception\RuntimeException
{
}
65 changes: 5 additions & 60 deletions src/OpenSearch/Common/Exceptions/Serializer/JsonErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,69 +21,14 @@

namespace OpenSearch\Common\Exceptions\Serializer;

use OpenSearch\Exception\OpenSearchExceptionInterface;
// @phpstan-ignore classConstant.deprecatedClass
@trigger_error(JsonErrorException::class . ' is deprecated in 2.4.0 and will be removed in 3.0.0. Use \OpenSearch\Exception\JsonErrorException instead.', E_USER_DEPRECATED);

/**
* Class JsonErrorException
*
* @deprecated in 2.4.0 and will be removed in 3.0.0. Use \OpenSearch\Exception\JsonErrorException instead.
*/
class JsonErrorException extends \Exception implements OpenSearchExceptionInterface
class JsonErrorException extends \OpenSearch\Exception\JsonException
{
/**
* @var mixed
*/
private $input;

/**
* @var mixed
*/
private $result;

/**
* @var string[]
*/
private static $messages = array(
JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded',
JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON',
JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded',
JSON_ERROR_SYNTAX => 'Syntax error',
JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded',
JSON_ERROR_RECURSION => 'One or more recursive references in the value to be encoded',
JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded',
JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given',

// JSON_ERROR_* constant values that are available on PHP >= 7.0
9 => 'Decoding of value would result in invalid PHP property name', //JSON_ERROR_INVALID_PROPERTY_NAME
10 => 'Attempted to decode nonexistent UTF-16 code-point' //JSON_ERROR_UTF16
);

/**
* @param mixed $input
* @param mixed $result
*/
public function __construct(int $code, $input, $result, ?\Throwable $previous = null)
{
if (isset(self::$messages[$code]) !== true) {
throw new \InvalidArgumentException(sprintf('Encountered unknown JSON error code: [%d]', $code));
}

parent::__construct(self::$messages[$code], $code, $previous);
$this->input = $input;
$this->result = $result;
}

/**
* @return mixed
*/
public function getInput()
{
return $this->input;
}

/**
* @return mixed
*/
public function getResult()
{
return $this->result;
}
}
8 changes: 6 additions & 2 deletions src/OpenSearch/Common/Exceptions/UnexpectedValueException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@

namespace OpenSearch\Common\Exceptions;

use OpenSearch\Exception\OpenSearchExceptionInterface;
// @phpstan-ignore classConstant.deprecatedClass
@trigger_error(UnexpectedValueException::class . ' is deprecated in 2.4.0 and will be removed in 3.0.0. Use \OpenSearch\Exception\UnexpectedValueException instead.', E_USER_DEPRECATED);

class UnexpectedValueException extends \UnexpectedValueException implements OpenSearchExceptionInterface
/**
* @deprecated in 2.4.0 and will be removed in 3.0.0. Use \OpenSearch\Exception\UnexpectedValueException instead.
*/
class UnexpectedValueException extends \OpenSearch\Exception\UnexpectedValueException
{
}
2 changes: 1 addition & 1 deletion src/OpenSearch/Endpoints/AbstractEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

namespace OpenSearch\Endpoints;

use OpenSearch\Common\Exceptions\UnexpectedValueException;
use OpenSearch\EndpointInterface;
use OpenSearch\Exception\UnexpectedValueException;
use OpenSearch\Serializers\SerializerInterface;

use function array_filter;
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSearch/Endpoints/AsyncSearch/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace OpenSearch\Endpoints\AsyncSearch;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Exception\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

class Delete extends AbstractEndpoint
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSearch/Endpoints/AsyncSearch/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace OpenSearch\Endpoints\AsyncSearch;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Exception\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

class Get extends AbstractEndpoint
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSearch/Endpoints/AsynchronousSearch/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace OpenSearch\Endpoints\AsynchronousSearch;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Exception\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSearch/Endpoints/AsynchronousSearch/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace OpenSearch\Endpoints\AsynchronousSearch;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Exception\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace OpenSearch\Endpoints\Cluster;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Exception\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace OpenSearch\Endpoints\Cluster;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Exception\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace OpenSearch\Endpoints\Cluster;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Exception\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSearch/Endpoints/Cluster/GetWeightedRouting.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace OpenSearch\Endpoints\Cluster;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Exception\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSearch/Endpoints/Cluster/PutComponentTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace OpenSearch\Endpoints\Cluster;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Exception\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace OpenSearch\Endpoints\Cluster;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Exception\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSearch/Endpoints/Cluster/PutWeightedRouting.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace OpenSearch\Endpoints\Cluster;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Exception\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSearch/Endpoints/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace OpenSearch\Endpoints;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Exception\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSearch/Endpoints/CreatePit.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace OpenSearch\Endpoints;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Exception\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace OpenSearch\Endpoints\DanglingIndices;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Exception\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace OpenSearch\Endpoints\DanglingIndices;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Exception\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace OpenSearch\Endpoints\DataFrameTransformDeprecated;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Exception\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

class DeleteTransform extends AbstractEndpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace OpenSearch\Endpoints\DataFrameTransformDeprecated;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Exception\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

class GetTransformStats extends AbstractEndpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace OpenSearch\Endpoints\DataFrameTransformDeprecated;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Exception\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

class PutTransform extends AbstractEndpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace OpenSearch\Endpoints\DataFrameTransformDeprecated;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Exception\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

class StartTransform extends AbstractEndpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace OpenSearch\Endpoints\DataFrameTransformDeprecated;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Exception\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

class StopTransform extends AbstractEndpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace OpenSearch\Endpoints\DataFrameTransformDeprecated;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Exception\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

class UpdateTransform extends AbstractEndpoint
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSearch/Endpoints/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace OpenSearch\Endpoints;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Exception\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSearch/Endpoints/DeleteByQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace OpenSearch\Endpoints;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Exception\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSearch/Endpoints/DeleteByQueryRethrottle.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace OpenSearch\Endpoints;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Exception\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSearch/Endpoints/DeleteScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace OpenSearch\Endpoints;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Exception\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSearch/Endpoints/Exists.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace OpenSearch\Endpoints;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Exception\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSearch/Endpoints/ExistsSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace OpenSearch\Endpoints;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Exception\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSearch/Endpoints/Explain.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace OpenSearch\Endpoints;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Exception\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSearch/Endpoints/FlowFramework/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace OpenSearch\Endpoints\FlowFramework;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Exception\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

/**
Expand Down
Loading

0 comments on commit 289a387

Please sign in to comment.