Skip to content

Commit

Permalink
unicode fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
jmagoon committed Jul 25, 2024
1 parent 357ef1e commit 944886f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions zetaforge/forge_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,22 @@ def setup(server_version, client_version, driver, build_flag = True, install_fla
mixpanel_client.track_event("Setup Successful")
return config_path

def safe_decode(byte_string, encodings=['utf-8', 'windows-1252']):
for encoding in encodings:
try:
return byte_string.decode(encoding)
except UnicodeDecodeError:
continue
# If all specified encodings fail, fall back to ISO-8859-1 (latin-1)
return byte_string.decode('iso-8859-1', errors='replace')

def read_output(process, name):
for line in process.stdout:
print(f"{name}: {line.decode('utf-8')}", end='')
print(f"{name}: {safe_decode(line)}", end='')

def read_error(process, name):
for line in process.stderr:
print(f"{name} (stderr): {line.decode('utf-8')}", end='')
print(f"{name} (stderr): {safe_decode(line)}", end='')

#dev version is only passed, when a developer wants to pass a local version(for e.g. dev_path=./s2-v2.3.5-amd64)
def run_forge(server_version=None, client_version=None, server_path=None, client_path=None, is_dev=False, no_sandbox=False):
Expand Down

0 comments on commit 944886f

Please sign in to comment.