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

[DX] Show the ParseException message in all YAML file loaders #36501

Merged

Conversation

fancyweb
Copy link
Contributor

@fancyweb fancyweb commented Apr 20, 2020

Q A
Branch? 3.4
Bug fix? no
New feature? no
Deprecations? no
Tickets -
License MIT
Doc PR -

This PR synchronizes the exception message in the Routing, Validator and Translation YAML file loaders with the DependencyInjection YAML file loader behavior. Adding the ParseException message is a big DX gain because it highlights the problem directly instead of having to scroll down 7 previous exceptions.

I'm targetting 3.4 because DX can be considered as a bug fix AFAIK.

@carsonbot carsonbot added Status: Needs Review DX DX = Developer eXperience (anything that improves the experience of using Symfony) labels Apr 20, 2020
@xabbuh xabbuh added this to the 3.4 milestone Apr 20, 2020
@nicolas-grekas
Copy link
Member

as @stof spotted, all these should be moved outside sprintf()

@nicolas-grekas
Copy link
Member

(but this is for master)

@javiereguiluz
Copy link
Member

This is great! Thanks a lot @fancyweb!

I tested it in the Symfony Demo app and the difference is huge:

Before

before

After

after

@fabpot
Copy link
Member

fabpot commented Apr 22, 2020

Idea: instead of selectively add the previous exception message to the current exception message, what about doing something similar to some Go error handling libraries where the end message of an error is always the concatenation of all error messages. That's something we could do only in the exception page/profiler.

@fancyweb
Copy link
Contributor Author

as @stof spotted, all these should be moved outside sprintf()

You mean concatenating the exception message after the sprintf? sprintf('The file "%s" does not contain valid YAML', $file).': '.$e->getMessage()

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Apr 22, 2020

@fancyweb yes - we should also fix existing messages.

@fancyweb fancyweb force-pushed the dx-yaml-parse-exception-file-loaders branch from d57b602 to fc6cf3d Compare April 23, 2020 14:19
@fancyweb
Copy link
Contributor Author

I fixed the existing message in the DI YamlFileLoader. Should I apply fabbot exception message formatting here, ie get rid of the : and just concatenate with a space + $e->getMessage()?

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Apr 26, 2020

Showing all stacked messages in a more prominent way is absolutely required I agree. The error page currently is not clear enough in this regard (I recently stayed stuck on an exception because I missed the 2nd one which provided the real issue.)

Doing both this change and improving the error page looks like what we should do IMHO. The reason is that we don't have full control over all situations where error messages are used; e.g. exceptions in logs, etc.

Still for master on my side - at least that's the policy we've had in the past: that's improving something.

@javiereguiluz
Copy link
Member

I agree with @nicolas-grekas about the possible improvements in the error page. We'll discuss about this in the coming weeks to have it ready for Symfony 5.2 👍

@nicolas-grekas
Copy link
Member

Thank you @fancyweb.

@nicolas-grekas nicolas-grekas merged commit 78a7f46 into symfony:3.4 May 4, 2020
@fancyweb fancyweb deleted the dx-yaml-parse-exception-file-loaders branch May 4, 2020 13:38
This was referenced May 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX DX = Developer eXperience (anything that improves the experience of using Symfony) Routing Status: Reviewed Translation Validator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants