Skip to content

Commit

Permalink
Throw exception when no server name inside game settings ini
Browse files Browse the repository at this point in the history
  • Loading branch information
bostrt committed Feb 12, 2024
1 parent ccff77a commit 1c75685
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/palworld_exporter/collectors/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
server_name_re = re.compile(r'^DedicatedServerName=(?P<name>.*?)$')


def find_server_name(filename: str) -> str | None:
def find_server_name(filename: str) -> str:
with open(filename, 'r') as f:
for line in f.readlines():
m = server_name_re.search(line)
if m:
return m.group("name")
return ""


def find_save_directory(starting_dir: str) -> str:
Expand Down Expand Up @@ -45,6 +46,8 @@ def find_save_directory(starting_dir: str) -> str:
return save_path[0]
else:
raise ValueError("Error automatically finding save directory")
else:
raise ValueError("GameUserSettings.ini found but it contains no DedicatedServerName")
elif len(result) == 0:
raise FileNotFoundError("No GameUserSettings.ini found")
elif len(result) > 1:
Expand Down

0 comments on commit 1c75685

Please sign in to comment.