Skip to content

Commit bd8c2cc

Browse files
committed
Strip 'Runtime error: ' and ' (19)' from Turso error messages
Turso prefixes constraint errors with 'Runtime error: ' and appends the raw SQLite error code. Tests compare against SQLite's native format, so normalise at rethrow time.
1 parent b9e534d commit bd8c2cc

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

.github/workflows/phpunit-tests-turso.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,24 @@ jobs:
543543
open(path, 'w').write(src)
544544
print('patched PRAGMA foreign_key_check')
545545
546-
# 3. wp_die polyfill: real WordPress provides wp_die(); the unit-test
546+
# 3. Turso prefixes constraint errors with "Runtime error: " which
547+
# SQLite doesn't. It also appends " (19)" (the SQLite error code)
548+
# to some messages. Tests compare against the SQLite format, so
549+
# strip Turso's extra decoration when rethrowing.
550+
old = "\t\t\tthrow $this->new_driver_exception( $e->getMessage(), $e->getCode(), $e );"
551+
new = (
552+
"\t\t\t$msg = $e->getMessage();\n"
553+
"\t\t\t// Normalise Turso-specific decoration to SQLite format.\n"
554+
"\t\t\t$msg = preg_replace( '/(?<=: )Runtime error: /', '', $msg );\n"
555+
"\t\t\t$msg = preg_replace( '/ \\(19\\)$/', '', $msg );\n"
556+
"\t\t\tthrow $this->new_driver_exception( $msg, $e->getCode(), $e );"
557+
)
558+
assert old in src, 'rethrow block not found'
559+
src = src.replace(old, new, 1)
560+
open(path, 'w').write(src)
561+
print('patched Turso error-message normalisation')
562+
563+
# 4. wp_die polyfill: real WordPress provides wp_die(); the unit-test
547564
# bootstrap doesn't, so tests hit an 'undefined function' error when
548565
# a driver error path tries to call it.
549566
path = 'tests/bootstrap.php'

0 commit comments

Comments
 (0)