Conversation
|
it looks like the database schema was changed very recently so I'll make sure to resolve any conflicts soon |
backend/utils/db.py
Outdated
| if record is None: | ||
| raise RecordNotFoundError(f"No snack found with SKU {sku}") | ||
| return Snack(**record) | ||
| except sqlite3.Error as e: | ||
| raise DatabaseError(f"Database error in fetching snack {sku}: {str(e)}") |
There was a problem hiding this comment.
This is raising a RecordNotFoundError but isn't being caught because the catch block is only catching sqlite3.Error
| cursor.execute("""SELECT sku FROM snacks WHERE sku = ?""", (snack.sku,)) | ||
| existing = cursor.fetchone() | ||
| if existing is not None: | ||
| raise DuplicateRecordError(f"Snack with SKU {snack.sku} already exists") |
There was a problem hiding this comment.
this is raising a DuplicateRecordError but the catch block below is only catching sqlite3.Error instances
backend/utils/db.py
Outdated
| raise RecordNotFoundError(f"No snack found with SKU {sku}") | ||
| return Snack(**record) | ||
| except sqlite3.Error as e: | ||
| raise DatabaseError(f"Database error when fetching snack {sku}: {str(e)}") |
There was a problem hiding this comment.
This is raising a RecordNotFoundError but isn't being caught because the catch block is only catching sqlite3.Error
| if record is None: | ||
| raise RecordNotFoundError(f"No snack found with SKU: {sku}" ) | ||
| return Snack(**record) | ||
| except sqlite3.Error as e: | ||
| raise DatabaseError(f"Database error when fetching snack {sku}: {str(e)}") |
There was a problem hiding this comment.
This is raising a RecordNotFoundError but isn't being caught because the catch block is only catching sqlite3.Error
| connection.row_factory = sqlite3.Row | ||
| return connection | ||
| except sqlite3.Error as e: | ||
| raise ConnectionError(f"Failed to connect to database: {str(e)}") |
There was a problem hiding this comment.
don't think this is being caught in any catch blocks (since all the catch blocks are catching sqlite3.Error)
NicholasLe04
left a comment
There was a problem hiding this comment.
great work so far! left some requested changes.
backend/utils/db.py
Outdated
| except (sqlite3.Error, DatabaseError, ConnectionError, DatabaseInitError) as e: | ||
| raise DatabaseError(f"Database error when fetching snack {sku}: {str(e)}") | ||
| except (RecordNotFoundError) as e: | ||
| raise RecordNotFoundError(str(e)) |
There was a problem hiding this comment.
the second catch block is actually unreachable because RecordNotFoundError is a subclass of DatabaseError which is caught first
| except (sqlite3.Error, DatabaseError, ConnectionError, DatabaseInitError) as e: | |
| raise DatabaseError(f"Database error when fetching snack {sku}: {str(e)}") | |
| except (RecordNotFoundError) as e: | |
| raise RecordNotFoundError(str(e)) | |
| except RecordNotFoundError as e: | |
| raise RecordNotFoundError(str(e)) | |
| except Exception as e: | |
| raise DatabaseError(f"Database error when fetching snack {sku}: {str(e)}") |
backend/utils/db.py
Outdated
| except (sqlite3.Error, DatabaseError, ConnectionError, DatabaseInitError) as e: | ||
| raise DatabaseError(f"Database error when fetching snack {sku}: {str(e)}") | ||
| except (RecordNotFoundError) as e: | ||
| raise RecordNotFoundError(str(e)) |
There was a problem hiding this comment.
the second catch block is actually unreachable because RecordNotFoundError is a subclass of DatabaseError which is caught first
| except (sqlite3.Error, DatabaseError, ConnectionError, DatabaseInitError) as e: | |
| raise DatabaseError(f"Database error when fetching snack {sku}: {str(e)}") | |
| except (RecordNotFoundError) as e: | |
| raise RecordNotFoundError(str(e)) | |
| except RecordNotFoundError as e: | |
| raise RecordNotFoundError(str(e)) | |
| except Exception as e: | |
| raise DatabaseError(f"Database error when deleting snack {sku}: {str(e)}") |
backend/utils/db.py
Outdated
| except (sqlite3.Error, DatabaseError, ConnectionError, DatabaseInitError) as e: | ||
| raise DatabaseError(f"Database error when fetching snack {snack.sku}: {str(e)}") | ||
| except (DuplicateRecordError) as e: | ||
| raise DuplicateRecordError(str(e)) |
There was a problem hiding this comment.
the second catch block is actually unreachable because DuplicateRecordError is a subclass of DatabaseError which is caught first
| except (sqlite3.Error, DatabaseError, ConnectionError, DatabaseInitError) as e: | |
| raise DatabaseError(f"Database error when fetching snack {snack.sku}: {str(e)}") | |
| except (DuplicateRecordError) as e: | |
| raise DuplicateRecordError(str(e)) | |
| except DuplicateRecordError as e: | |
| raise DuplicateRecordError(str(e)) | |
| except Exception as e: | |
| raise DatabaseError(f"Database error when creating snack {snack.sku}: {str(e)}") |
backend/utils/db.py
Outdated
| except (sqlite3.Error, DatabaseError, ConnectionError, DatabaseInitError) as e: | ||
| raise DatabaseError(f"Database error in fetching snack {sku}: {str(e)}") | ||
| except (RecordNotFoundError) as e: | ||
| raise RecordNotFoundError(str(e)) |
There was a problem hiding this comment.
the second catch block is actually unreachable because RecordNotFoundError is a subclass of DatabaseError which is caught first
| except (sqlite3.Error, DatabaseError, ConnectionError, DatabaseInitError) as e: | |
| raise DatabaseError(f"Database error in fetching snack {sku}: {str(e)}") | |
| except (RecordNotFoundError) as e: | |
| raise RecordNotFoundError(str(e)) | |
| except RecordNotFoundError as e: | |
| raise RecordNotFoundError(str(e)) | |
| except Exception as e: | |
| raise DatabaseError(f"Database error in updating snack {sku}: {str(e)}") |
No description provided.