Skip to content

Commit c672dc6

Browse files
committed
Operation respone and meta on error
1 parent e198801 commit c672dc6

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

yandexcloud/_operation_waiter.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,44 +63,42 @@ def get_operation_result(
6363
operation_result: OperationResult[ResponseType, MetaType] = OperationResult(operation)
6464
created_at = datetime.fromtimestamp(operation.created_at.seconds)
6565
message = (
66-
"Running Yandex.Cloud operation. ID: {id}. "
67-
"Description: {description}. Created at: {created_at}. "
68-
"Created by: {created_by}."
69-
)
70-
message = message.format(
71-
id=operation.id,
72-
description=operation.description,
73-
created_at=created_at,
74-
created_by=operation.created_by,
66+
f"Running Yandex.Cloud operation. ID: {operation.id}. "
67+
f"Description: {operation.description}. Created at: {created_at}. "
68+
f"Created by: {operation.created_by}."
7569
)
70+
7671
if meta_type and meta_type is not Empty:
7772
unpacked_meta = meta_type()
7873
operation.metadata.Unpack(unpacked_meta)
7974
operation_result.meta = unpacked_meta
8075
message += f" Meta: {unpacked_meta}."
76+
8177
logger.info(message)
78+
8279
result = wait_for_operation(sdk, operation.id, timeout=timeout)
8380
if result is None:
84-
return OperationError(message="Unexpected operation result", operation_result=OperationResult(operation))
81+
raise OperationError(message="Unexpected operation result", operation_result=operation_result)
82+
8583
if result.error and result.error.code:
8684
error_message = (
87-
"Error Yandex.Cloud operation. ID: {id}. Error code: {code}. Details: {details}. Message: {message}."
88-
)
89-
error_message = error_message.format(
90-
id=result.id,
91-
code=result.error.code,
92-
details=result.error.details,
93-
message=result.error.message,
85+
f"Error Yandex.Cloud operation. ID: {result.id}. "
86+
f"Error code: {result.error.code}. "
87+
f"Details: {result.error.details}. "
88+
f"Message: {result.error.message}. "
89+
f"Meta: {operation_result.meta}."
9490
)
9591
logger.error(error_message)
96-
raise OperationError(message=error_message, operation_result=OperationResult(operation))
92+
raise OperationError(message=error_message, operation_result=operation_result)
9793

9894
log_message = f"Done Yandex.Cloud operation. ID: {operation.id}."
9995
if response_type and response_type is not Empty:
10096
unpacked_response = response_type()
10197
result.response.Unpack(unpacked_response)
10298
operation_result.response = unpacked_response
103-
log_message += f" Response: {unpacked_response}."
99+
log_message += f" Response: {operation_result.response}."
100+
log_message += f" Meta: {operation_result.meta}."
101+
104102
logger.info(log_message)
105103
return operation_result
106104

0 commit comments

Comments
 (0)