Skip to content

Commit

Permalink
BUGFIX: show error message if file is not writeable
Browse files Browse the repository at this point in the history
  • Loading branch information
amilcarlucas committed Apr 24, 2024
1 parent 6d8d698 commit 7b0f35e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 7 additions & 3 deletions MethodicConfigurator/backend_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,14 @@ def load_vehicle_components_json_data(self):
logging_error("Error decoding JSON data from file '%s'.", filepath)
return data

def save_vehicle_components_json_data(self, data):
def save_vehicle_components_json_data(self, data) -> bool:
filepath = os_path.join(self.vehicle_dir, self.vehicle_components_json_filename)
with open(filepath, 'w', encoding='utf-8') as file:
json_dump(data, file, indent=4)
try:
with open(filepath, 'w', encoding='utf-8') as file:
json_dump(data, file, indent=4)
except Exception as e:

Check failure on line 404 in MethodicConfigurator/backend_filesystem.py

View workflow job for this annotation

GitHub Actions / build (3.10)

Ruff (F841)

MethodicConfigurator/backend_filesystem.py:404:29: F841 Local variable `e` is assigned to but never used

Check failure on line 404 in MethodicConfigurator/backend_filesystem.py

View workflow job for this annotation

GitHub Actions / build (3.10)

Ruff (F841)

MethodicConfigurator/backend_filesystem.py:404:29: F841 Local variable `e` is assigned to but never used
return True
return False

def new_vehicle_dir(self, base_dir: str, new_dir: str):
return os_path.join(base_dir, new_dir)
Expand Down
7 changes: 5 additions & 2 deletions MethodicConfigurator/frontend_tkinter_component_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from backend_filesystem import LocalFilesystem

from frontend_tkinter_base import show_tooltip
from frontend_tkinter_base import show_error_message
from frontend_tkinter_base import ScrollFrame
from frontend_tkinter_base import BaseWindow

Expand Down Expand Up @@ -179,8 +180,10 @@ def save_data(self):
current_data[path[-1]] = value

# Save the updated data back to the JSON file
self.local_filesystem.save_vehicle_components_json_data(self.data)
logging_info("Data saved successfully.")
if self.local_filesystem.save_vehicle_components_json_data(self.data):
show_error_message("Error", "Failed to save data to file.")
else:
logging_info("Data saved successfully.")
self.root.destroy()


Expand Down

0 comments on commit 7b0f35e

Please sign in to comment.