Skip to content

EspoCRM – Open Source CRM Application

formula sandbox log errors

Yuri Kuznetsov72cd6583d5a9
diff --git a/application/Espo/Controllers/Formula.php b/application/Espo/Controllers/Formula.php
index 04977d75d9..669dc31218 100644
--- a/application/Espo/Controllers/Formula.php
+++ b/application/Espo/Controllers/Formula.php
@@ -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;
diff --git a/application/Espo/Tools/Formula/Service.php b/application/Espo/Tools/Formula/Service.php
index bad3538e1e..b53096dc18 100644
--- a/application/Espo/Tools/Formula/Service.php
+++ b/application/Espo/Tools/Formula/Service.php
@@ -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);
}