Skip to content

Conversation

shaohuzhang1
Copy link
Contributor

fix: improve error logging format for TencentCloudSDKException

Copy link

f2c-ci-robot bot commented Aug 14, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copy link

f2c-ci-robot bot commented Aug 14, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@@ -77,4 +77,4 @@ def speech_to_text(self, audio_file):


except TencentCloudSDKException as err:
print(err)
maxkb_logger.error(f":Error: {str(err)}: {traceback.format_exc()}")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The provided code looks mostly correct for logging errors using maxkb_logger. However, there're a few minor improvements you can make to enhance clarity and ensure proper formatting:

  1. Consistent Logging Format: Ensure that both print statements use the same format string to avoid any inconsistencies.

    Update the line with the error printing to match the other log entry formats:

            maxkb_logger.error(f":Error: {str(err)}\n{traceback.format_exc()}")
  2. Logging Level: If this is intended to be the default behavior of catching all exceptions during speech-to-text conversion, it might be more appropriate to use an informational level (logger.info) instead of error if no critical action needs to be taken immediately upon encountering an exception.

  3. Exception Handling Context: The original code seems to be handling only specific exceptions (assuming TencentCloudSDKException). Consider whether additional types of exceptions should also be caught and logged, especially depending on how robust your application needs to be.

Here's the revised code based on these considerations:

@@ -77,4 +77,4 @@ def speech_to_text(self, audio_file):
 
 
         except TencentCloudSDKException as err:
-            maxkb_logger.error(f":Error: {str(err)}")
+            maxkb_logger.exception(f":Error: {str(err)}")

or

@@ -77,4 +77,4 @@ def speech_to_text(self, audio_file):
 
 
         except Exception as err:
             maxkb_logger.error(f":Error: {str(err)}")

This change switches from print() to exception(), which logs the full traceback along with the error message at the ERROR level, providing better context about where the exception originated. Adjust the verbosity further up or down if needed based on your application requirements.

@liuruibin liuruibin merged commit 581143c into v2 Aug 14, 2025
3 of 6 checks passed
@liuruibin liuruibin deleted the pr@v2@fix_error branch August 14, 2025 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants