Skip to content

[LiveComponent] improve errors when LiveArg is missing for live action and live listener #1906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Symfony\Component\Security\Csrf\CsrfToken;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Symfony\Contracts\Service\ServiceSubscriberInterface;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
use Symfony\UX\LiveComponent\Attribute\LiveArg;
use Symfony\UX\LiveComponent\LiveComponentHydrator;
Expand Down Expand Up @@ -274,6 +275,14 @@ public function onKernelException(ExceptionEvent $event): void
return;
}

if ($event->getThrowable() instanceof RuntimeException) {
if (str_starts_with($event->getThrowable()->getMessage(), 'Could not resolve argument $key')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use a class/interface here?

$throwable = new RuntimeException('It look likes you trying to call a LiveAction or a LiveListener without the required arguments.
Please make sure the arguments of your action have a #[LiveArgument] in front of them.', $event->getThrowable()->getCode(), $event->getThrowable()->getPrevious());
$event->setThrowable($throwable);
}
}

if (!$event->getThrowable() instanceof UnprocessableEntityHttpException) {
return;
}
Expand Down