Friendly exception


(Alexander Makarov) #1

The concept of “friendly exception” is that one can implement FriendlyExceptionInterface and provide a possible solution to the problem exception represents. Error handler may display it along with usual exception information.

Initially it was part of yii-web package that already has an error handler capable of displaying it but thinking about it for a few days I realized that it’s both useful for console applications and usage outside of Yii.

Thus, I’ve extracted a really small package with an interface only:

What do you think about it?


#2

Why this package/repository is named friendlyexception instead of friendly-exception?


(Alexander Makarov) #3

Because namespace is FriendlyException and not Friendly\Exception. See https://github.com/yiisoft/docs/blob/master/004-namespaces.md


#4

This does not seems to be consequent (https://github.com/yiisoft/yii-auth-client/blob/master/composer.json or https://github.com/yiisoft/log-target-db/blob/master/composer.json) nor practical (ignoring words separators makes package name harder to read).


(Alexander Makarov) #5

These two were not touched yet so namespaces aren’t corrected. We can come up with another naming schema. If you have an idea, please propose.


#6

I’m not sure if creating direct relation between namespace and package name is a good idea (small change in namespace would require creating another package, and sometimes it will force creating longer namespaces or unnatural package names). But I’m definitely sure that ignoring words separators is a bad idea. Both Yiisoft\FooBar\Baz and Yiisoft\Foo\BarBaz should result foo-bar-baz as package name. Although theoretically this may create some conflicts, I doubt it will be a real problem.


(Dmitriy Derepko) #7

I think it crude useless package.

  1. What is the need to that interface? Why Exception::getMessage() don’t you satisfied?
  2. Why a package has name FriendlyExceptionInterface instead of SolutionProvidedExceptionInterface/SolutionableInterface/etc.?
  3. What is the need to separating from core framework repository?

(Alexander Makarov) #8

Because getMessage() is used not only to display purpose but for logging as well. Logging messages with solutions will make your log very bloated.

Because interface includes getName() as well. It was SolutionProviderInterface before.

Because exceptions may originate from non-core. For example, cache or RBAC.


(Alexander Makarov) #9

Package was renamed to yiisoft/friendly-exception.


#10

Have you thought about using Whoops as the default error handler?


Yii 2.0.28, extensions and Yii 3 progress
(Alexander Makarov) #11

Yes, I did. It doesn’t bring much to the table while missing some features.