Skip to content

Commit 3e4aef1

Browse files
abnegateclaude
andcommitted
fix: handle table already exists and no such table in SQLite processException
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c80db70 commit 3e4aef1

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/Database/Adapter/SQLite.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,16 @@ protected function processException(PDOException $e): \Exception
13121312
return new TimeoutException('Query timed out', $e->getCode(), $e);
13131313
}
13141314

1315+
// Table/index already exists (SQLITE_ERROR with "already exists" message)
1316+
if ($e->getCode() === 'HY000' && isset($e->errorInfo[1]) && $e->errorInfo[1] === 1 && stripos($e->getMessage(), 'already exists') !== false) {
1317+
return new DuplicateException('Collection already exists', $e->getCode(), $e);
1318+
}
1319+
1320+
// Table not found (SQLITE_ERROR with "no such table" message)
1321+
if ($e->getCode() === 'HY000' && isset($e->errorInfo[1]) && $e->errorInfo[1] === 1 && stripos($e->getMessage(), 'no such table') !== false) {
1322+
return new NotFoundException('Collection not found', $e->getCode(), $e);
1323+
}
1324+
13151325
// Duplicate - SQLite uses various error codes for constraint violations:
13161326
// - Error code 19 is SQLITE_CONSTRAINT (includes UNIQUE violations)
13171327
// - Error code 1 is also used for some duplicate cases
@@ -1320,7 +1330,6 @@ protected function processException(PDOException $e): \Exception
13201330
($e->getCode() === 'HY000' && isset($e->errorInfo[1]) && ($e->errorInfo[1] === 1 || $e->errorInfo[1] === 19)) ||
13211331
$e->getCode() === '23000'
13221332
) {
1323-
// Check if it's actually a duplicate/unique constraint violation
13241333
$message = $e->getMessage();
13251334
if (
13261335
(isset($e->errorInfo[1]) && $e->errorInfo[1] === 19) ||

0 commit comments

Comments
 (0)