Skip to content

Commit 1ae4f19

Browse files
committed
fix(user_status): add debug logging to silent failure paths
Multiple code paths in StatusService silently swallowed failures, making it impossible to debug status reliability issues. Add debug logging for: backup creation conflicts, aborted automated status changes, failed revert operations, and concurrent insert conflicts. AI-Assisted-By: Claude Opus 4.6 Signed-off-by: Anna Larch <anna@nextcloud.com>
1 parent 5c65719 commit 1ae4f19

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

apps/user_status/lib/Service/StatusService.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ public function setUserStatus(string $userId,
284284

285285
if ($createBackup) {
286286
if ($this->backupCurrentStatus($userId) === false) {
287+
$this->logger->debug('Automated status change aborted for user ' . $userId . ': backup already exists (another automated status is active)', ['app' => 'user_status']);
287288
return null; // Already a status set automatically => abort.
288289
}
289290

@@ -516,6 +517,7 @@ public function backupCurrentStatus(string $userId): bool {
516517
return true;
517518
} catch (Exception $ex) {
518519
if ($ex->getReason() === Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
520+
$this->logger->debug('Backup status already exists for user ' . $userId . ', skipping backup creation', ['app' => 'user_status']);
519521
return false;
520522
}
521523
throw $ex;
@@ -533,7 +535,7 @@ public function revertUserStatus(string $userId, string $messageId, bool $revert
533535

534536
$deleted = $this->mapper->deleteCurrentStatusToRestoreBackup($userId, $messageId);
535537
if (!$deleted) {
536-
// Another status is set automatically or no status, do nothing
538+
$this->logger->debug('Status revert skipped for user ' . $userId . ': current status does not match messageId "' . $messageId . '" (user may have changed status manually)', ['app' => 'user_status']);
537539
return null;
538540
}
539541

@@ -589,10 +591,10 @@ protected function insertWithoutThrowingUniqueConstrain(UserStatus $userStatus):
589591
try {
590592
return $this->mapper->insert($userStatus);
591593
} catch (Exception $e) {
592-
// Ignore if a parallel request already set the status
593594
if ($e->getReason() !== Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
594595
throw $e;
595596
}
597+
$this->logger->debug('Concurrent insert conflict for user ' . $userStatus->getUserId() . ': status was already set by a parallel request', ['app' => 'user_status']);
596598
}
597599
return $userStatus;
598600
}

0 commit comments

Comments
 (0)