From d85ad2066e367e5882691aaeda96e6cf0e551c9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Eckel?= Date: Wed, 1 Feb 2023 12:14:20 +0100 Subject: [PATCH] catching Tarantool exceptions in case of concurrency (implicitly issued by the planetmint-diver-ts tests) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jürgen Eckel --- CHANGELOG.md | 3 +++ planetmint/version.py | 2 +- planetmint/web/views/base.py | 7 +++++-- planetmint/web/views/outputs.py | 10 +++++++++- planetmint/web/views/transactions.py | 13 +++++++++---- 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a30970..71bfe01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,9 @@ For reference, the possible headings are: * **Known Issues** * **Notes** +## [2.2.2] - 2023-31-01 +* **Fixed** catching tarantool exceptions in case tarantool drivers throw execeptions due to concurrency issues. This issue got idenitfied during the testing of the planetmint-driver-ts. + ## [2.2.0] - 2023-31-01 * **Changed** standardized blocks API diff --git a/planetmint/version.py b/planetmint/version.py index 4b94d70..0c3bc4d 100644 --- a/planetmint/version.py +++ b/planetmint/version.py @@ -3,7 +3,7 @@ # SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0) # Code is Apache-2.0 and docs are CC-BY-4.0 -__version__ = "2.2.1" +__version__ = "2.2.2" __short_version__ = "2.2" # Supported Tendermint versions diff --git a/planetmint/web/views/base.py b/planetmint/web/views/base.py index d4b7f36..1572c8b 100644 --- a/planetmint/web/views/base.py +++ b/planetmint/web/views/base.py @@ -14,7 +14,7 @@ from planetmint.config import Config logger = logging.getLogger(__name__) -def make_error(status_code, message=None): +def make_error(status_code, message=None, level: str = "debug"): if status_code == 404 and message is None: message = "Not found" @@ -22,7 +22,10 @@ def make_error(status_code, message=None): request_info = {"method": request.method, "path": request.path} request_info.update(response_content) - logger.debug("HTTP API error: %(status)s - %(method)s:%(path)s - %(message)s", request_info) + if level == "error": + logger.error("HTTP API error: %(status)s - %(method)s:%(path)s - %(message)s", request_info) + else: + logger.debug("HTTP API error: %(status)s - %(method)s:%(path)s - %(message)s", request_info) response = jsonify(response_content) response.status_code = status_code diff --git a/planetmint/web/views/outputs.py b/planetmint/web/views/outputs.py index 9b4992c..6a3ae9e 100644 --- a/planetmint/web/views/outputs.py +++ b/planetmint/web/views/outputs.py @@ -6,6 +6,7 @@ from flask import current_app from flask_restful import reqparse, Resource from planetmint.web.views import parameters +from planetmint.web.views.base import make_error class OutputListApi(Resource): @@ -23,5 +24,12 @@ class OutputListApi(Resource): pool = current_app.config["bigchain_pool"] with pool() as planet: - outputs = planet.get_outputs_filtered(args["public_key"], args["spent"]) + try: + outputs = planet.get_outputs_filtered(args["public_key"], args["spent"]) + except Exception as e: + return make_error( + 500, + "Invalid output ({}): {} : {} - {}".format(type(e).__name__, e, args["public_key"], args["spent"]), + level="error", + ) return [{"transaction_id": output.txid, "output_index": output.output} for output in outputs] diff --git a/planetmint/web/views/transactions.py b/planetmint/web/views/transactions.py index 39fe56c..ff46be8 100644 --- a/planetmint/web/views/transactions.py +++ b/planetmint/web/views/transactions.py @@ -73,7 +73,6 @@ class TransactionListApi(Resource): # `force` will try to format the body of the POST request even if the # `content-type` header is not set to `application/json` tx = request.get_json(force=True) - try: tx_obj = Transaction.from_dict(tx, False) except SchemaValidationError as e: @@ -82,15 +81,21 @@ class TransactionListApi(Resource): message="Invalid transaction schema: {}".format(e.__cause__.message), ) except KeyError as e: - return make_error(400, "Invalid transaction ({}): {}".format(type(e).__name__, e)) + return make_error(400, "Invalid transaction ({}): {} : {}".format(type(e).__name__, e, tx)) except ValidationError as e: - return make_error(400, "Invalid transaction ({}): {}".format(type(e).__name__, e)) + return make_error(400, "Invalid transaction ({}): {} : {}".format(type(e).__name__, e, tx)) + except Exception as e: + return make_error(500, "Invalid transaction ({}): {} : {}".format(type(e).__name__, e, tx), level="error") with pool() as planet: try: planet.validate_transaction(tx_obj) except ValidationError as e: - return make_error(400, "Invalid transaction ({}): {}".format(type(e).__name__, e)) + return make_error(400, "Invalid transaction ({}): {} :{}".format(type(e).__name__, e, tx)) + except Exception as e: + return make_error( + 500, "Invalid transaction ({}): {} : {}".format(type(e).__name__, e, tx), level="error" + ) else: if tx_obj.version != Transaction.VERSION: return make_error(