Skip to content
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

[Form] Rethrow/log transformation exception #5607

Closed
rcambrj opened this issue Sep 26, 2012 · 4 comments
Closed

[Form] Rethrow/log transformation exception #5607

rcambrj opened this issue Sep 26, 2012 · 4 comments
Labels
Feature Form Good first issue Ideal for your first contribution! (some Symfony experience may be required)

Comments

@rcambrj
Copy link

rcambrj commented Sep 26, 2012

If a Transformer throws a TransformationFailedException, the details of this exception are lost.

https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Form.php line 592:

        } catch (TransformationFailedException $e) {
            $this->synchronized = false;
        }

The exception code+message should probably be kept and displayed.

Instead, the error becomes "This value is not valid.". I've not been able to find out how, but this message occurs in:
https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php

Related:
#4860
#703

@marekkalnik
Copy link
Contributor

+1 for this. I've just spent 3 evenings debugging a transformation error. There should be at least a possibility to log this kind of errors.

@webmozart
Copy link
Contributor

Thank you for taking the time to report this issue! I will tag this as a feature request.

@jbcrestot
Copy link

Hi,
The code and message shouldn't be displayed since, it's technical error. I'm trying to find out a solution to log the error.
The Form object is instantiated by the formBuilder (https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/FormBuilder.php#L220), but I'm not sure if I should pass the logger, via the config parameter or add new one?

webmozart added a commit that referenced this issue Sep 30, 2014
…onstraint violation (webmozart)

This PR was merged into the 2.6-dev branch.

Discussion
----------

[Validator] Made it possible to store the cause of a constraint violation

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | yes
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | TODO

This change makes it possible to store the cause of a violation (e.g. an exception). This way it is possible to follow the trace of violations caused by exceptions up to their root.

```php
try {
    // ...
} catch (Exception $e) {
    $this->context->buildViolation('Error!')
        ->setCause($e)
        ->addViolation();
}
```

This is one step to solve #5607. See #12054.

Commits
-------

499eeb4 [Validator] Made it possible to store the cause of a constraint violation
webmozart added a commit that referenced this issue Sep 30, 2014
…e profiler (webmozart)

This PR was merged into the 2.6-dev branch.

Discussion
----------

[Form] The trace of form errors is now displayed in the profiler

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | yes
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #5607
| License       | MIT
| Doc PR        | -

This is a follow-up PR for #12052. With this change, the full trace of form errors is now displayed in the web debugger:

![error](https://cloud.githubusercontent.com/assets/176399/4419637/85facd14-456d-11e4-8c70-0e8802a586ec.png)

If a violation was caused by a TransformationFailedException, the exception is now accessible through the `getCause()` method of the violation. Additionally, you can access `Form::getTransformationFailure()` to retrieve the exception.

Commits
-------

8dbe258 [Form] The trace of form errors is now displayed in the profiler
@webmozart
Copy link
Contributor

Fixed in #12054.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Form Good first issue Ideal for your first contribution! (some Symfony experience may be required)
Projects
None yet
Development

No branches or pull requests

5 participants