@@ -505,22 +505,46 @@ def execute_queued_items(self):
505
505
# something went wrong
506
506
# (includes DB file not found, transaction processing issue, db locked)
507
507
except sqlite3 .Error as e :
508
+ # Detailed error codes are only available for python >= 3.11
509
+ if hasattr (e , "sqlite_errorcode" ):
510
+ error_code = str (e .sqlite_errorcode )
511
+ else :
512
+ error_code = "Not available"
513
+
514
+ if hasattr (e , "sqlite_errorname" ):
515
+ error_name = e .sqlite_errorname
516
+ else :
517
+ error_name = "Not available"
518
+
508
519
if not self .is_public :
509
520
# incase this isn't a filesystem issue, log the statements
510
521
# which make up the transaction to assist debug
511
522
LOG .error (
512
- 'An error occurred when writing to the database,'
523
+ 'An error occurred when writing to the database %(file)s ,'
513
524
' this is probably a filesystem issue.'
514
- f' The attempted transaction was:\n { pformat (sql_queue )} '
525
+ ' The error was: %(error)s'
526
+ ' SQLite error code: %(error_code)s'
527
+ ' SQLite error name: %(error_name)s'
528
+ ' The attempted transaction was:\n %(transaction)s' % {
529
+ "file" : self .db_file_name ,
530
+ "error" : str (e ),
531
+ "error_code" : error_code ,
532
+ "error_name" : error_name ,
533
+ "transaction" : pformat (sql_queue )
534
+ }
515
535
)
516
536
raise
517
537
self .n_tries += 1
518
538
LOG .warning (
519
539
"%(file)s: write attempt (%(attempt)d)"
520
- " did not complete: %(error)s\n " % {
540
+ " did not complete: %(error)s\n "
541
+ " SQLite error code: %(error_code)s\n "
542
+ " SQLite error name: %(error_name)s" % {
521
543
"file" : self .db_file_name ,
522
544
"attempt" : self .n_tries ,
523
- "error" : str (e )
545
+ "error" : str (e ),
546
+ "error_code" : error_code ,
547
+ "error_name" : error_name
524
548
}
525
549
)
526
550
if self .conn is not None :
@@ -565,15 +589,15 @@ def _execute_stmt(self, stmt, stmt_args_list):
565
589
try :
566
590
self .connect ()
567
591
self .conn .executemany (stmt , stmt_args_list )
568
- except sqlite3 .Error :
592
+ except sqlite3 .Error as e :
569
593
if not self .is_public :
570
594
raise
571
595
if cylc .flow .flags .verbosity > 1 :
572
596
traceback .print_exc ()
573
597
err_log = (
574
598
"cannot execute database statement:\n "
575
- "file=%(file)s:\n stmt=%(stmt)s"
576
- ) % {"file" : self .db_file_name , "stmt" : stmt }
599
+ "file=%(file)s:\n stmt=%(stmt)s\n error=%(error)s "
600
+ ) % {"file" : self .db_file_name , "stmt" : stmt , "error" : str ( e ) }
577
601
for i , stmt_args in enumerate (stmt_args_list ):
578
602
err_log += ("\n stmt_args[%(i)d]=%(stmt_args)s" % {
579
603
"i" : i , "stmt_args" : stmt_args })
0 commit comments