Skip to content

Commit

Permalink
Added extra check if a spool has no filament
Browse files Browse the repository at this point in the history
  • Loading branch information
Donkie committed Jun 28, 2023
1 parent 64aaf2a commit bbe1dc0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion spoolman/database/spool.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Optional

import sqlalchemy
from sqlalchemy.exc import NoResultFound
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import contains_eager, joinedload

Expand Down Expand Up @@ -198,7 +199,10 @@ async def use_length(db: AsyncSession, spool_id: int, length: float) -> models.S
.join(models.Spool, models.Spool.filament_id == models.Filament.id)
.where(models.Spool.id == spool_id),
)
filament_info = result.one()
try:
filament_info = result.one()
except NoResultFound as exc:
raise ItemNotFoundError("Filament not found for spool.") from exc

# Calculate and use weight
weight = weight_from_length(
Expand Down

0 comments on commit bbe1dc0

Please sign in to comment.