error handling for vdf

This commit is contained in:
Roy 2024-06-19 12:32:05 -07:00 committed by GitHub
parent 4f77e05dfb
commit cc2b4053ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -197,9 +197,15 @@ else:
shortcuts = {'shortcuts': {}} shortcuts = {'shortcuts': {}}
except Exception as e: except Exception as e:
print(f"Error reading shortcuts file: {e}") print(f"Error reading shortcuts file: {e}")
# If an error occurs when reading the file, create a new file with an empty "shortcuts" section print("Please check the file and try again.")
with open(shortcuts_file, 'wb') as file: return
vdf.binary_dumps({'shortcuts': {}}, file)
# Check data integrity before writing to file
if shortcuts and isinstance(shortcuts, dict) and 'shortcuts' in shortcuts:
with open(shortcuts_file, 'wb') as file:
vdf.binary_dumps(shortcuts, file)
else:
print("The data to be written to the shortcuts file is not valid.")
# Open the config.vdf file # Open the config.vdf file