formula sandbox log errors

This commit is contained in:
Yuri Kuznetsov
2025-03-25 13:42:23 +02:00
parent 03969a20fe
commit 72cd6583d5
2 changed files with 27 additions and 23 deletions

View File

@@ -30,31 +30,33 @@
namespace Espo\Controllers;
use Espo\Core\Api\Request;
use Espo\Core\Exceptions\NotFoundSilent;
use Espo\Tools\Formula\Service;
use Espo\Core\Exceptions\BadRequest;
use Espo\Core\Exceptions\ForbiddenSilent;
use Espo\Entities\User;
use Espo\Core\Field\LinkParent;
use stdClass;
class Formula
{
private Service $service;
public function __construct(Service $service, User $user)
{
$this->service = $service;
/**
* @throws ForbiddenSilent
*/
public function __construct(
private Service $service,
User $user,
) {
if (!$user->isAdmin()) {
throw new ForbiddenSilent();
}
}
/**
* @throws BadRequest
*/
public function postActionCheckSyntax(Request $request): stdClass
{
$expression = $request->getParsedBody()->expression ?? null;
@@ -66,6 +68,10 @@ class Formula
return $this->service->checkSyntax($expression)->toStdClass();
}
/**
* @throws BadRequest
* @throws NotFoundSilent
*/
public function postActionRun(Request $request): stdClass
{
$expression = $request->getParsedBody()->expression ?? null;

View File

@@ -34,26 +34,19 @@ use Espo\Core\Formula\Exceptions\SyntaxError;
use Espo\Core\Formula\Exceptions\Error;
use Espo\Core\Formula\Manager;
use Espo\Core\Field\LinkParent;
use Espo\Core\Exceptions\NotFoundSilent;
use Espo\Core\Utils\Log;
use Espo\ORM\EntityManager;
use Espo\ORM\Entity;
class Service
{
private Parser $parser;
private Manager $manager;
private EntityManager $entityManager;
public function __construct(Parser $parser, Manager $manager, EntityManager $entityManager)
{
$this->parser = $parser;
$this->manager = $manager;
$this->entityManager = $entityManager;
}
public function __construct(
private Parser $parser,
private Manager $manager,
private EntityManager $entityManager,
private Log $log,
) {}
public function checkSyntax(string $expression): SyntaxCheckResult
{
@@ -68,6 +61,9 @@ class Service
return $result;
}
/**
* @throws NotFoundSilent
*/
public function run(string $expression, ?LinkParent $targetLink = null): RunResult
{
$syntaxCheckResult = $this->checkSyntax($expression);
@@ -96,6 +92,8 @@ class Service
} catch (Error $e) {
$output = $variables->__output ?? null;
$this->log->error("Formula sandbox run error.", ['exception' => $e->getPrevious()]);
return RunResult::createError($e, $output);
}