@@ -505,22 +505,46 @@ def execute_queued_items(self):
505505 # something went wrong
506506 # (includes DB file not found, transaction processing issue, db locked)
507507 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+
508519 if not self .is_public :
509520 # incase this isn't a filesystem issue, log the statements
510521 # which make up the transaction to assist debug
511522 LOG .error (
512- 'An error occurred when writing to the database,'
523+ 'An error occurred when writing to the database %(file)s ,'
513524 ' 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+ }
515535 )
516536 raise
517537 self .n_tries += 1
518538 LOG .warning (
519539 "%(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" % {
521543 "file" : self .db_file_name ,
522544 "attempt" : self .n_tries ,
523- "error" : str (e )
545+ "error" : str (e ),
546+ "error_code" : error_code ,
547+ "error_name" : error_name
524548 }
525549 )
526550 if self .conn is not None :
@@ -565,15 +589,15 @@ def _execute_stmt(self, stmt, stmt_args_list):
565589 try :
566590 self .connect ()
567591 self .conn .executemany (stmt , stmt_args_list )
568- except sqlite3 .Error :
592+ except sqlite3 .Error as e :
569593 if not self .is_public :
570594 raise
571595 if cylc .flow .flags .verbosity > 1 :
572596 traceback .print_exc ()
573597 err_log = (
574598 "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 ) }
577601 for i , stmt_args in enumerate (stmt_args_list ):
578602 err_log += ("\n stmt_args[%(i)d]=%(stmt_args)s" % {
579603 "i" : i , "stmt_args" : stmt_args })
0 commit comments