Skip to content

Commit

Permalink
Fix issue IMGIITRoorkee#1- Error handling for password Manager.
Browse files Browse the repository at this point in the history
Added a specific `except FileNotFoundError` block to catch missing files.
- Added a generic `except Exception` block to handle any unexpected errors and provide a meaningful error message.
- The program now continues running smoothly and provides helpful feedback when a user attempts to load a non-existent password file.

This improves the robustness of the program, ensuring a smoother user experience by preventing crashes due to missing files.
  • Loading branch information
stutijain2006 authored Dec 16, 2024
1 parent 6220200 commit 684aaf2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ def create_password_file(self, path, initial_values=None):

def load_password_file(self, path):
self.password_file = path
with open(path, 'r') as f:
for line in f:
site, encrypted = line.split(":")
self.password_dict[site] = Fernet(self.key).decrypt(encrypted.encode()).decode()
try:
with open(path, 'r') as f:
for line in f:
site, encrypted = line.split(":")
self.password_dict[site] = Fernet(self.key).decrypt(encrypted.encode()).decode()
except FileNotFoundError:
print("Password file at ", path, "was not found. Please do check the file path and try again.")
except Exception as e:
print("An unexpected error occured: ", e)

def add_password(self, site, password):
self.password_dict[site] = password
Expand Down

0 comments on commit 684aaf2

Please sign in to comment.