mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-24 18:04:32 +02:00
Raise TransactionError instead of RuntimeError from enable_wal/disable_wal
A dedicated sqlite_utils.db.TransactionError exception is clearer to catch than a generic RuntimeError, and gives future transaction-state guards a home. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UnLnhsH25Nnv7LHhekUfPd
This commit is contained in:
parent
788c393a30
commit
96793668ed
5 changed files with 14 additions and 9 deletions
|
|
@ -301,6 +301,10 @@ class InvalidColumns(Exception):
|
|||
"Specified columns do not exist"
|
||||
|
||||
|
||||
class TransactionError(Exception):
|
||||
"Operation cannot be performed while a transaction is open"
|
||||
|
||||
|
||||
class DescIndex(str):
|
||||
pass
|
||||
|
||||
|
|
@ -891,7 +895,7 @@ class Database:
|
|||
"""
|
||||
Sets ``journal_mode`` to ``'wal'`` to enable Write-Ahead Log mode.
|
||||
|
||||
:raises RuntimeError: if called while a transaction is open - the
|
||||
:raises TransactionError: if called while a transaction is open - the
|
||||
journal mode can only be changed outside of a transaction
|
||||
"""
|
||||
if self.journal_mode != "wal":
|
||||
|
|
@ -903,7 +907,7 @@ class Database:
|
|||
"""
|
||||
Sets ``journal_mode`` back to ``'delete'`` to disable Write-Ahead Log mode.
|
||||
|
||||
:raises RuntimeError: if called while a transaction is open - the
|
||||
:raises TransactionError: if called while a transaction is open - the
|
||||
journal mode can only be changed outside of a transaction
|
||||
"""
|
||||
if self.journal_mode != "delete":
|
||||
|
|
@ -916,7 +920,7 @@ class Database:
|
|||
# any open transaction as a side effect - breaking the rollback
|
||||
# guarantee of atomic() and of user-managed transactions
|
||||
if self.conn.in_transaction:
|
||||
raise RuntimeError(
|
||||
raise TransactionError(
|
||||
"{} cannot be used while a transaction is open".format(operation)
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue