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

Exception issue #517

Closed
puschie286 opened this issue May 23, 2017 · 5 comments
Closed

Exception issue #517

puschie286 opened this issue May 23, 2017 · 5 comments

Comments

@puschie286
Copy link
Contributor

Hey, i found a problem with the error_exception.php after calling a anonymous function with too few arguments.

the exceptionHandler has the right data ( correct type, code, message etc. ) so i guess its something in the error_exception.php

Exampe Code to reproduce ( i call this in a model ) :
public function ExceptionTest() { $exampleFunc = function( $a, $b ) { }; $exampleFunc( null ); }

Output is :
`ErrorException #1

Uncaught ReflectionException: Method App\Models\Mitarbeiter::App\Models{closure}() does not exist in C:\WorkSpace\PHPPlayground\CodeIgniter4\application\Views\errors\html\error_exception.php:91 Stack trace: #0 C:\WorkSpace\PHPPlayground\CodeIgniter4\application\Views\errors\html\error_exception.php(91): ReflectionMethod->__construct('App\Models\Mita...', 'App\Models\{clo...') #1 C:\WorkSpace\PHPPlayground\CodeIgniter4\system\Debug\Exceptions.php(151): include('C:\WorkSpace\PH...') #2 [internal function]: CodeIgniter\Debug\Exceptions->exceptionHandler(Object(ArgumentCountError)) #3 {main} thrown `
error

if you need more informations feel free to ask :)

@lonnieezell
Copy link
Member

I'm not sure what I can do to fix this. It happens because you're calling a closure with the incorrect number of parameters. When we attempt to examine it with new ReflectionMethod it is unable to find a closure with one parameter and that name and throw its own Exception. You're hitting an issue with the language itself, not CI. The only option we have is to not try to display values passed to the functions, but that's such a handy feature when debugging that I'm not sure it makes sense to remove that for this edge case.

@puschie286
Copy link
Contributor Author

puschie286 commented May 29, 2017

well i just wondering why the exceptionHandler has the right data but does not display it ( and shows a ( for me ) unclear error description ). there are much more cases that are results in something like this - i know such errors should be found by development tools, but not all do it right.
it would be a nice improvement in consistency and easier ( and faster ) error understanding

@lonnieezell
Copy link
Member

You're right, it would be simpler, but what's happening is that while reporting an exception from something in your script (in this case the missing parameter), it tries to use Reflection to describe the parameters in that method. Which is then throwing another exception because the ReflectionMethod itself fails when it encounters that specific situation (a Closure with a missing parameter).

My current belief is that the frequency we'll hit cases when we run into this is a very very small percentage of the time, and that the ability to inspect the parameters passed into methods the rest of the time is more important. Obviously, we'll monitor this as more people get to use it and see if it becomes a bigger issue than I think it will be. If that's true, then we'll decide what to do then.

If you can create a better solution and submit a pull request, I'm more than happy to look at it.

@puschie286
Copy link
Contributor Author

hey, found a simple solution : #551

@lonnieezell
Copy link
Member

Thanks! I was going to start looking into that soon since I realized it's a bigger issue than I thought it was originally while working on the Template Engine blog post this week.

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

No branches or pull requests

2 participants