Fix error reporting
This commit is contained in:
parent
76f76f73b4
commit
a4db37adfa
|
|
@ -1068,13 +1068,33 @@ public function process(Import $import, ?Authenticatable $user = null): array
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
|
$rollbackFailed = false;
|
||||||
|
$rollbackError = null;
|
||||||
if ($isPg) {
|
if ($isPg) {
|
||||||
// Roll back only this row's work
|
// Roll back only this row's work
|
||||||
try {
|
try {
|
||||||
DB::statement('ROLLBACK TO SAVEPOINT import_row_'.$rowNum);
|
DB::statement('ROLLBACK TO SAVEPOINT import_row_'.$rowNum);
|
||||||
} catch (\Throwable $ignored) { /* noop */
|
} catch (\Throwable $ignored) {
|
||||||
|
$rollbackFailed = true;
|
||||||
|
$rollbackError = $ignored;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($rollbackFailed) {
|
||||||
|
// Abort the whole import if we cannot rollback to the row savepoint (transaction is poisoned)
|
||||||
|
ImportEvent::create([
|
||||||
|
'import_id' => $import->id,
|
||||||
|
'user_id' => $user?->getAuthIdentifier(),
|
||||||
|
'event' => 'row_rollback_failed',
|
||||||
|
'level' => 'error',
|
||||||
|
'message' => 'Rollback to savepoint failed; aborting import.',
|
||||||
|
'context' => [
|
||||||
|
'row_number' => $rowNum,
|
||||||
|
'exception' => $this->exceptionContext($rollbackError ?? $e),
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw $rollbackError ?? $e;
|
||||||
|
}
|
||||||
// Ensure importRow exists for logging if failure happened before its creation
|
// Ensure importRow exists for logging if failure happened before its creation
|
||||||
if (! $importRow) {
|
if (! $importRow) {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user