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>
31 lines
705 B
PHP
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;
|
|
}
|
|
}
|
|
}
|