mirror of
https://github.com/aljazceru/dev-gpt.git
synced 2026-01-25 00:14:18 +01:00
⛰ fix: prevent large string content in error message
This commit is contained in:
@@ -18,7 +18,7 @@ from jina import Flow
|
||||
|
||||
from dev_gpt.constants import DEMO_TOKEN
|
||||
from dev_gpt.utils.io import suppress_stdout, is_docker_running
|
||||
from dev_gpt.utils.string_tools import print_colored
|
||||
from dev_gpt.utils.string_tools import print_colored, clean_large_words
|
||||
|
||||
|
||||
def wait_until_app_is_ready(url):
|
||||
@@ -309,6 +309,7 @@ def clean_color_codes(response):
|
||||
response = re.sub(r'\x1b\[[0-9;]*m', '', response)
|
||||
return response
|
||||
|
||||
|
||||
def process_error_message(error_message):
|
||||
lines = error_message.split('\n')
|
||||
|
||||
@@ -330,10 +331,12 @@ def process_error_message(error_message):
|
||||
|
||||
response = clean_color_codes(response)
|
||||
|
||||
# the following code makes sure that the error message is cleaned from irrelevant sequences of e.g. base64 strings.
|
||||
response = clean_large_words(response)
|
||||
|
||||
# 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
|
||||
# but the last line of the error message will start with "error"
|
||||
|
||||
last_line = lines[-1]
|
||||
if not response and last_line.startswith('error: '):
|
||||
return last_line
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
import platform
|
||||
import string
|
||||
import re
|
||||
|
||||
if platform.system() == "Windows":
|
||||
os.system("color")
|
||||
@@ -39,4 +40,10 @@ def get_template_parameters(formatted_string):
|
||||
if field_name is not None:
|
||||
parameters.append(field_name)
|
||||
|
||||
return parameters
|
||||
return parameters
|
||||
|
||||
def clean_large_words(text):
|
||||
"""Large words like base64 strings are returned by omitting the middle part of the word."""
|
||||
pattern = r'\b([a-zA-Z0-9+/]{20})([a-zA-Z0-9+/]{200,})([a-zA-Z0-9+/]{20})\b'
|
||||
cleaned_text = re.sub(pattern, r'\1...\3', text)
|
||||
return cleaned_text
|
||||
Reference in New Issue
Block a user