mirror of
https://github.com/aljazceru/dev-gpt.git
synced 2025-12-21 15:44:19 +01:00
🎨 fix: color codes in error (#26)
This commit is contained in:
@@ -265,6 +265,10 @@ def shorten_logs(relevant_lines):
|
|||||||
return relevant_lines
|
return relevant_lines
|
||||||
|
|
||||||
|
|
||||||
|
def clean_color_codes(response):
|
||||||
|
response = re.sub(r'\x1b\[[0-9;]*m', '', response)
|
||||||
|
return response
|
||||||
|
|
||||||
def process_error_message(error_message):
|
def process_error_message(error_message):
|
||||||
lines = error_message.split('\n')
|
lines = error_message.split('\n')
|
||||||
|
|
||||||
@@ -284,6 +288,8 @@ def process_error_message(error_message):
|
|||||||
|
|
||||||
response = '\n'.join(relevant_lines[-100:]).strip()
|
response = '\n'.join(relevant_lines[-100:]).strip()
|
||||||
|
|
||||||
|
response = clean_color_codes(response)
|
||||||
|
|
||||||
# the following code tests the case that the docker file is corrupted and can not be parsed
|
# the following code tests the case that the docker file is corrupted and can not be parsed
|
||||||
# the method above will not return a relevant error message in this case
|
# the method above will not return a relevant error message in this case
|
||||||
# but the last line of the error message will start with "error"
|
# but the last line of the error message will start with "error"
|
||||||
|
|||||||
11
test/test_strings.py
Normal file
11
test/test_strings.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
from src.apis.jina_cloud import clean_color_codes
|
||||||
|
|
||||||
|
|
||||||
|
def test_clean_color_codes():
|
||||||
|
color_start = f"\033[{31}m"
|
||||||
|
reset = "\033[0m"
|
||||||
|
bold_start = "\033[1m"
|
||||||
|
color = f"{bold_start}{color_start}test{reset}"
|
||||||
|
cleaned = clean_color_codes(color)
|
||||||
|
print('with color codes:', color)
|
||||||
|
print('without color codes:', cleaned)
|
||||||
Reference in New Issue
Block a user