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

Custom Error Formatter #648

Open
uphlewis opened this issue Aug 12, 2020 · 2 comments
Open

Custom Error Formatter #648

uphlewis opened this issue Aug 12, 2020 · 2 comments

Comments

@uphlewis
Copy link

Hi!

First of all, thanks so much for psysh, it is absolutely fundamental to my development process these days as im sure it is for many others.

Suggestion / request for comment

It would be nice to be able to specify a custom error formatter (e.g., closure) which receives the exception/throwable, and the output instance as arguments. Either a custom formatter, or at least the ability to hook into the Shell::writeException() method and e.g., write additional output to aid debugging for certain types of errors.

One example of this is in laravel projects, when a validation exception is thrown. Psysh outputs the error message, but the real substance of those exceptions is the $e->errors() array, which contains the exact validation errors which is crucial for debugging.

To demonstrate, this is the current behaviour:
image

What I'm aiming to be able to achieve:
image

Obviously there are myriad ways this could be achieved, i have a couple of ideas of how to implement a custom formatter as an optional configuration option in a safe/sensible way and am willing to prepare a PR, if this is an addition you'd be welcome to seeing in the project.

Thanks

@bobthecow
Copy link
Owner

Conceptually this feels in line with the way we use var-dumper and casters. I could get on board with it.

It'd be ideal if we could come up with a way for this to work and be useful without needing additional configuration, and without duplicating a bunch of stuff already done in var-dumper. Maybe using var-dumper automatically if there's an explicitly defined caster for that exception type? Maybe doing something with caster filters, and extending our Presenter with a presentException?

@uphlewis
Copy link
Author

Sounds great- id have to get into the package a little more and see how casters work with var dumper. But happy to contribute something if I can!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants