Skip to content

Commit

Permalink
Inform for which field the configuration errored
Browse files Browse the repository at this point in the history
  • Loading branch information
sstok committed Sep 16, 2024
1 parent 5c3d247 commit ce7d3c3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/Core/Field/GenericResolvedFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Rollerworks\Component\Search\Value\Compare;
use Rollerworks\Component\Search\Value\PatternMatch;
use Rollerworks\Component\Search\Value\Range;
use Symfony\Component\OptionsResolver\Exception\ExceptionInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
Expand Down Expand Up @@ -70,7 +71,11 @@ public function getTypeExtensions(): array

public function createField(string $name, array $options = []): FieldConfig
{
$options = $this->getOptionsResolver()->resolve($options);
try {
$options = $this->getOptionsResolver()->resolve($options);
} catch (ExceptionInterface $e) {
throw new $e(\sprintf('An error has occurred resolving the options of the field "%s" with type "%s": ', $name, get_debug_type($this->getInnerType())) . $e->getMessage(), $e->getCode(), $e);
}

return $this->newField($name, $options);
}
Expand Down
8 changes: 7 additions & 1 deletion lib/Core/GenericSearchFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Rollerworks\Component\Search\Field\FieldConfig;
use Rollerworks\Component\Search\Field\OrderField;
use Rollerworks\Component\Search\Field\TypeRegistry;
use Symfony\Component\OptionsResolver\Exception\ExceptionInterface;

/**
* @author Sebastiaan Stok <[email protected]>
Expand Down Expand Up @@ -64,7 +65,12 @@ public function createField(string $name, string $type, array $options = []): Fi
private function createOptionsForOrderField(string $name, array $options): array
{
$type = $this->registry->getType($options['type']);
$options['type_options'] = $type->getOptionsResolver()->resolve($options['type_options'] ?? []);

try {
$options['type_options'] = $type->getOptionsResolver()->resolve($options['type_options'] ?? []);
} catch (ExceptionInterface $e) {
throw new $e(\sprintf('An error has occurred resolving the type-options of the order-field "%s"": ', $name) . $e->getMessage(), $e->getCode(), $e);
}

return $options;
}
Expand Down

0 comments on commit ce7d3c3

Please sign in to comment.