Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Handle unknown plants
Browse files Browse the repository at this point in the history
If a plant has the THICKET_GUID but is not found in the database,
don't crash, but notify the user in the N panel and provide the operator
to rebuild the database.

Avoid similar problems in the general case when the plant count is 0. To
be useful, the user will have to rebuild the database, so make that
obvious and easy to find.

Signed-off-by: Darren Hart <[email protected]>
  • Loading branch information
dvhart committed Apr 25, 2020
1 parent c91e9a9 commit 32b9dfa
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def thicket_init():
except FileNotFoundError:
logging.info("Database not found, creating empty database")

if db is None:
if db is None or db.plant_count() == 0:
thicket_status = ThicketStatus.REBUILD_DB
db_dir = Path(PurePath(db_path).parent)
db_dir.mkdir(parents=True, exist_ok=True)
Expand Down Expand Up @@ -874,6 +874,11 @@ def draw(self, context):
return

plant = db.get_plant(name=tp.name)
if plant is None:
layout.label(text="Plant not found in database")
layout.operator("thicket.rebuild_db", icon="FILE_REFRESH")
return

layout.template_icon(icon_value=get_preview(plant.name, tp.model).icon_id, scale=THICKET_SCALE)
if thicket_ui_mode == 'VIEW':
o = layout.operator("thicket.edit_plant")
Expand Down

0 comments on commit 32b9dfa

Please sign in to comment.