Files
WP-LIT-MCP/src/Abilities/FollowUp.php
T
janniclas.loosenandClaude Opus 5.5 b6984d3f9a refactor: one logging helper LIT\MCP\Log (M6)
Log::failure(context, detail) keeps the '[wp-lit-mcp] <context> failed: <detail>'
format of the nine former error_log() sites; Log::line() covers the change log line.
One phpcs ignore instead of eleven.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 17:36:01 +02:00

31 lines
705 B
PHP

<?php
declare(strict_types=1);
namespace LIT\MCP\Abilities;
use LIT\MCP\Log;
use Throwable;
/**
* Runs a step after a write has already succeeded (listeners, change log): a failure
* there must not turn the saved change into an error. It is logged and reported as warning.
*/
final class FollowUp
{
/**
* @param list<string> $warnings Receives $warning when the step fails.
*/
public static function run(callable $step, string $context, string $warning, array &$warnings): mixed
{
try {
return $step();
} catch (Throwable $e) {
Log::failure($context, $e);
$warnings[] = $warning;
return null;
}
}
}