Skip to content

Commit

Permalink
Fixes missing rules exception message
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro committed Nov 20, 2023
1 parent 0a79505 commit 5b29e1d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
5 changes: 0 additions & 5 deletions src/Actions/CallMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Livewire\Volt\Actions;

use Closure;
use Livewire\Exceptions\MissingRulesException;
use Livewire\Exceptions\PropertyNotFoundException;
use Livewire\Volt\CompileContext;
use Livewire\Volt\Component;
Expand Down Expand Up @@ -42,10 +41,6 @@ public function execute(CompileContext $context, Component $component, array $ar
$e, "State definition for [$propertyName] not found on component [{$component->voltComponentName()}]."
);

throw $e;
} catch (MissingRulesException $e) {
Reflection::setExceptionMessage($e, "[rules()] declaration not found in [{$component->voltComponentName()}].");

throw $e;
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/LivewireManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Livewire\Volt;

use Livewire\Exceptions\MethodNotFoundException;
use Livewire\Exceptions\MissingRulesException;
use Livewire\LivewireManager as BaseLivewireManager;
use Livewire\Volt\Actions\InitializeState;
use Livewire\Volt\Support\Reflection;
Expand Down Expand Up @@ -43,6 +44,17 @@ public function update($snapshot, $diff, $calls)
Reflection::setExceptionMessage($e, "Method or action [$method] does not exist on component [{$componentInstance->voltComponentName()}].");
}

throw $e;
} catch (MissingRulesException $e) {
$componentInstance = $this->current();

if ($componentInstance instanceof Component) {
Reflection::setExceptionMessage(
$e,
"Missing [\$rules/rules()] property/method on: [{$componentInstance->voltComponentName()}].",
);
}

throw $e;
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/ClassComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
->call('store');
})->throws(
MissingRulesException::class,
'Missing [$rules/rules()] property/method on Livewire component: [component-with-missing-rules].',
'Missing [$rules/rules()] property/method on: [component-with-missing-rules].',
);

it('throws exception when method is not found within action', function () {
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/FunctionalComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public function render()
->call('store');
})->throws(
MissingRulesException::class,
'[rules()] declaration not found in [component-with-missing-rules].',
'Missing [$rules/rules()] property/method on: [component-with-missing-rules].',
);

it('throws exception when method is not found within action', function () {
Expand Down

0 comments on commit 5b29e1d

Please sign in to comment.