Create servers list if do not exists

Otherwise, if the configuration file do not have 'SERVERS' array, ogCP
crashes trying to append a new server.
async-tree
Javier Sánchez Parra 2022-09-22 17:37:10 +02:00
parent 178f253092
commit 328ead9168
1 changed files with 5 additions and 1 deletions

View File

@ -1507,7 +1507,11 @@ def save_server(form):
with open(filename, 'r+') as file:
config = json.load(file)
config['SERVERS'].append(server_dict)
try:
config['SERVERS'].append(server_dict)
except KeyError:
config['SERVERS'] = list()
config['SERVERS'].append(server_dict)
file.seek(0)
json.dump(config, file, indent='\t')