Skip to content

Commit 7eb5288

Browse files
committed
fixing bug with too long string in messages
1 parent 9d66955 commit 7eb5288

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

python/install-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
build==1.2.1
2-
build-tool @ https://github.com/GamuNetwork/devtools/releases/download/1.5.8/build_tool-1.5.8-py3-none-any.whl
2+
build-tool @ https://github.com/GamuNetwork/devtools/releases/download/1.6.8/build_tool-1.6.8-py3-none-any.whl
33
exceptiongroup==1.2.1
44
iniconfig==2.0.0
55
packaging==24.0

python/src/gamuLogger/utils.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,22 +123,29 @@ def wrapper(*args, **kwargs):
123123
return func(*args, **kwargs)
124124
return wrapper
125125

126+
def countLinesLength(string : str) -> list[int]:
127+
lines = string.split('\n')
128+
return [len(line) for line in lines]
129+
126130
def splitLongString(string : str, length : int = 100) -> str:
127131
"""Split a long string into multiple lines, on spaces"""
128132
result = []
129133
if len(string) <= length:
130134
return string
131135

132-
tokens = string.split(' ')
133-
line = ""
134-
for token in tokens:
135-
if len(token) > length:
136-
raise ValueError(f"Word '{token}' is too long (limit is {length} characters)")
137-
if len(line) + len(token) > length:
138-
result.append(line.strip())
139-
line = ""
140-
line += token + ' '
141-
result.append(line.strip())
136+
lines = [line.split(' ') for line in string.split('\n')]
137+
138+
for line in lines:
139+
current_line = []
140+
for word in line:
141+
if len(word) > length:
142+
raise ValueError("A word is longer than the maximum length")
143+
if len(' '.join(current_line)) + len(word) > length:
144+
result.append(' '.join(current_line))
145+
current_line = [word]
146+
else:
147+
current_line.append(word)
148+
result.append(' '.join(current_line))
142149
return '\n'.join(result)
143150

144151
class CustomJSONEncoder(JSONEncoder):

0 commit comments

Comments
 (0)