Skip to content

Commit

Permalink
handling sql errors in file
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianTremblay committed Aug 26, 2024
1 parent 62f599a commit 49c90c8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion BAC0/core/devices/Device.py
Original file line number Diff line number Diff line change
Expand Up @@ -1067,14 +1067,14 @@ async def initialize_device_from_db(self):
# Save important properties for reuse
if self.properties.db_name:
dbname = self.properties.db_name
self._props = self.read_dev_prop(self.properties.db_name)
else:
self.log("Missing argument DB", level="info")
raise ValueError("Please provide db name using device.load_db('name')")

# network = self.properties.network
pss = self.properties.pss

self._props = self.read_dev_prop(self.properties.db_name)
self.points = []
for point in self.points_from_sql(self.properties.db_name):
try:
Expand Down
8 changes: 6 additions & 2 deletions BAC0/db/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,5 +291,9 @@ def read_dev_prop(self, device_name):
Device properties retrieved from pickle
"""
self.log("Reading prop from DB file", level="debug")
with open(f"{device_name}.bin", "rb") as file:
return pickle.load(file)["device"]
try:
with open(f"{device_name}.bin", "rb") as file:
return pickle.load(file)["device"]
except EOFError:
self._log.error("Error reading device properties")
raise ValueError

0 comments on commit 49c90c8

Please sign in to comment.