catching Tarantool exceptions in case of concurrency (implicitly issued by the planetmint-diver-ts tests)

Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
Jürgen Eckel 2023-02-01 12:14:20 +01:00
parent 87506ff4a1
commit d85ad2066e
No known key found for this signature in database
5 changed files with 27 additions and 8 deletions

View File

@ -25,6 +25,9 @@ For reference, the possible headings are:
* **Known Issues** * **Known Issues**
* **Notes** * **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 ## [2.2.0] - 2023-31-01
* **Changed** standardized blocks API * **Changed** standardized blocks API

View File

@ -3,7 +3,7 @@
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0) # SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
# Code is Apache-2.0 and docs are 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" __short_version__ = "2.2"
# Supported Tendermint versions # Supported Tendermint versions

View File

@ -14,7 +14,7 @@ from planetmint.config import Config
logger = logging.getLogger(__name__) 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: if status_code == 404 and message is None:
message = "Not found" message = "Not found"
@ -22,7 +22,10 @@ def make_error(status_code, message=None):
request_info = {"method": request.method, "path": request.path} request_info = {"method": request.method, "path": request.path}
request_info.update(response_content) 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 = jsonify(response_content)
response.status_code = status_code response.status_code = status_code

View File

@ -6,6 +6,7 @@
from flask import current_app from flask import current_app
from flask_restful import reqparse, Resource from flask_restful import reqparse, Resource
from planetmint.web.views import parameters from planetmint.web.views import parameters
from planetmint.web.views.base import make_error
class OutputListApi(Resource): class OutputListApi(Resource):
@ -23,5 +24,12 @@ class OutputListApi(Resource):
pool = current_app.config["bigchain_pool"] pool = current_app.config["bigchain_pool"]
with pool() as planet: 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] return [{"transaction_id": output.txid, "output_index": output.output} for output in outputs]

View File

@ -73,7 +73,6 @@ class TransactionListApi(Resource):
# `force` will try to format the body of the POST request even if the # `force` will try to format the body of the POST request even if the
# `content-type` header is not set to `application/json` # `content-type` header is not set to `application/json`
tx = request.get_json(force=True) tx = request.get_json(force=True)
try: try:
tx_obj = Transaction.from_dict(tx, False) tx_obj = Transaction.from_dict(tx, False)
except SchemaValidationError as e: except SchemaValidationError as e:
@ -82,15 +81,21 @@ class TransactionListApi(Resource):
message="Invalid transaction schema: {}".format(e.__cause__.message), message="Invalid transaction schema: {}".format(e.__cause__.message),
) )
except KeyError as e: 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: 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: with pool() as planet:
try: try:
planet.validate_transaction(tx_obj) planet.validate_transaction(tx_obj)
except ValidationError as e: 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: else:
if tx_obj.version != Transaction.VERSION: if tx_obj.version != Transaction.VERSION:
return make_error( return make_error(