feat: log plugin runtime errors

This commit is contained in:
Marek Miklewicz
2026-06-02 22:57:23 +02:00
parent 7561077eee
commit 86eb1dddbd
8 changed files with 110 additions and 12 deletions
+1
View File
@@ -18,6 +18,7 @@ return static function (AppContext $ctx): void {
}
Http::redirect($ctx->url('index.html', ['status' => 'created']));
} catch (Throwable $e) {
PluginLogger::exception($e, 'CREATE');
$errors[] = $e->getMessage();
}
}
+1
View File
@@ -16,6 +16,7 @@ return static function (AppContext $ctx): void {
$ctx->audit->record('delete', $ctx->daUser->username(), ['rule_id' => $id, 'subject_prefix' => (string)($rule['subject_prefix'] ?? $rule['subject'] ?? '')]);
Http::redirect($ctx->url('index.html', ['status' => 'deleted']));
} catch (Throwable $e) {
PluginLogger::exception($e, 'DELETE');
$ctx->render('Confirm deletion', '<div class="alert alert-err">' . AppContext::e($e->getMessage()) . '</div>');
return;
}
+16 -11
View File
@@ -2,16 +2,21 @@
declare(strict_types=1);
return static function (AppContext $ctx): void {
$ctx->requirePost();
$id = $ctx->post('id');
$ctx->requireCsrf('toggle:' . $id);
$rule = $ctx->rules->find($ctx->daUser->username(), $id);
if ($rule === null) {
throw new RuntimeException($ctx->t('Rule not found'));
try {
$ctx->requirePost();
$id = $ctx->post('id');
$ctx->requireCsrf('toggle:' . $id);
$rule = $ctx->rules->find($ctx->daUser->username(), $id);
if ($rule === null) {
throw new RuntimeException($ctx->t('Rule not found'));
}
$next = ['enabled' => empty($rule['enabled'])];
enforce_rule_backend_constraints($ctx, $id, $next);
$ctx->rules->update($ctx->daUser->username(), $id, $next);
$ctx->syncActiveBackend();
Http::redirect($ctx->url('index.html', ['status' => 'toggled']));
} catch (Throwable $e) {
PluginLogger::exception($e, 'TOGGLE');
throw $e;
}
$next = ['enabled' => empty($rule['enabled'])];
enforce_rule_backend_constraints($ctx, $id, $next);
$ctx->rules->update($ctx->daUser->username(), $id, $next);
$ctx->syncActiveBackend();
Http::redirect($ctx->url('index.html', ['status' => 'toggled']));
};
+1
View File
@@ -19,6 +19,7 @@ return static function (AppContext $ctx): void {
$ctx->syncActiveBackend();
Http::redirect($ctx->url('index.html', ['status' => 'updated']));
} catch (Throwable $e) {
PluginLogger::exception($e, 'UPDATE');
$errors[] = $e->getMessage();
}
}