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

The problem in catching exceptions #1274

Closed
demortx opened this issue Sep 30, 2018 · 8 comments
Closed

The problem in catching exceptions #1274

demortx opened this issue Sep 30, 2018 · 8 comments

Comments

@demortx
Copy link

demortx commented Sep 30, 2018

The problem occurs when you create a global variable with an object of any class, except that it handles the variables only to an array, but when it receives an exception in the global variable, it throws an internal error.

#0 [internal function]: CodeIgniter\Debug\Exceptions->shutdownHandler()
#1 {main}
CRITICAL - 2018-09-28 20:33:03 --> Undefined variable: is_install
#0 /var/www/web.ru/application/Modules/Globals/Module/func.php(209): CodeIgniter\Debug\Exceptions->errorHandler(8, 'Undefined varia...', '/var/www/web.r..', 209, Array)
#1 /var/www/web.ru/application/Modules/Globals/Module/Module.php(49): Module\func->ajax_add_ons_renewal()
#2 /var/www/web.ru/application/Controllers/Main.php(234): App\Modules\Globals\Module\Module->App\Modules\Globals\Module\{closure}()
#3 /var/www/web.ru/system/CodeIgniter.php(807): App\Controllers\Main->ajax()
#4 /var/www/web.ru/system/CodeIgniter.php(305): CodeIgniter\CodeIgniter->runController(Object(App\Controllers\Main))
#5 /var/www/web.ru/system/CodeIgniter.php(220): CodeIgniter\CodeIgniter->handleRequest(NULL, Object(Config\Cache), false)
#6 /var/www/web.ru/public_html/index.php(37): CodeIgniter\CodeIgniter->run()
#7 {main}
CRITICAL - 2018-09-28 20:33:03 --> Uncaught CodeIgniter\Format\Exceptions\FormatException: Failed to parse json string, error: "Recursion detected". in /var/www/web.ru/system/Format/Exceptions/FormatException.php:9
Stack trace:
#0 /var/www/web.ru/system/Format/JSONFormatter.php(61): CodeIgniter\Format\Exceptions\FormatException::forInvalidJSON('Recursion detec...')
#1 /var/www/web.ru/system/API/ResponseTrait.php(367): CodeIgniter\Format\JSONFormatter->format(Array)
#2 /var/www/web.ru/system/API/ResponseTrait.php(120): CodeIgniter\Debug\Exceptions->format(Array)
#3 /var/www/web.ru/system/Debug/Exceptions.php(147): CodeIgniter\Debug\Exceptions->respond(Array, 500)
#4 [internal function]: CodeIgniter\Debug\Exceptions->exceptionHandler(Object(ErrorException))
#5 {main}
  thrown
#0 [internal function]: CodeIgniter\Debug\Exceptions->shutdownHandler()
#1 {main}

It is easy to see that first the exception is normally worked out, and then it is covered by a mistake from the exception itself, and in this case the error is only visible in the log

Sorry for Google translator from Russian

@puschie286
Copy link
Contributor

puschie286 commented Oct 1, 2018

it looks like the ResponseTrait::format / ResponseTrait::respond failed to handle the response correctly

could you provide/post the array you use in the response function call - its pretty hard to understand the callstack without any data

@lonnieezell
Copy link
Member

Yes, please provide additional details on how to recreate. I'm having a hard time following this one.

@demortx
Copy link
Author

demortx commented Oct 15, 2018

I can't fully reproduce the bug, but here’s another one that got

$options = [
'base_uri' => 'you.com', // need returned error: 403 Forbidden
'timeout' => 1
];
$client = \Config\Services::curlrequest($options);
$response = $client->get('api/config'); <

and we see an error here again

as you can see the first error returns us -> 403 Forbidden
but for what reason does the whole script fly away to the exception, I understand it is clear

#0 [internal function]: CodeIgniter\Debug\Exceptions->shutdownHandler()
#1 {main}
CRITICAL - 2018-10-15 13:21:42 --> 22 : The requested URL returned error: 403 Forbidden
#0 /var/www/main.you.ru/system/HTTP/CURLRequest.php(741): CodeIgniter\HTTP\Exceptions\HTTPException::forCurlError('22', 'The requested U...')
#1 /var/www/main.you.ru/system/HTTP/CURLRequest.php(377): CodeIgniter\HTTP\CURLRequest->sendRequest(Array)
#2 /var/www/main.you.ru/system/HTTP/CURLRequest.php(148): CodeIgniter\HTTP\CURLRequest->send('get', 'https://mw4.you...')
#3 /var/www/main.you.ru/system/HTTP/CURLRequest.php(165): CodeIgniter\HTTP\CURLRequest->request('get', 'https://mw4.you...', Array)
#4 /var/www/main.you.ru/application/API/v1/System/Upload.php(23): CodeIgniter\HTTP\CURLRequest->get('api/config')
#5 /var/www/main.you.ru/system/CodeIgniter.php(807): App\API\v1\System\Upload->config()
#6 /var/www/main.you.ru/system/CodeIgniter.php(305): CodeIgniter\CodeIgniter->runController(Object(App\API\v1\System\Upload))
#7 /var/www/main.you.ru/system/CodeIgniter.php(220): CodeIgniter\CodeIgniter->handleRequest(NULL, Object(Config\Cache), false)
#8 /var/www/main.you.ru/public_html/index.php(37): CodeIgniter\CodeIgniter->run()
#9 {main}
CRITICAL - 2018-10-15 13:21:42 --> Uncaught CodeIgniter\Format\Exceptions\FormatException: Failed to parse json string, error: "Type is not supported". in /var/www/main.you.ru/system/Format/Exceptions/FormatException.php:9
Stack trace:
#0 /var/www/main.you.ru/system/Format/JSONFormatter.php(61): CodeIgniter\Format\Exceptions\FormatException::forInvalidJSON('Type is not sup...')
#1 /var/www/main.you.ru/system/API/ResponseTrait.php(367): CodeIgniter\Format\JSONFormatter->format(Array)
#2 /var/www/main.you.ru/system/API/ResponseTrait.php(120): CodeIgniter\Debug\Exceptions->format(Array)
#3 /var/www/main.you.ru/system/Debug/Exceptions.php(147): CodeIgniter\Debug\Exceptions->respond(Array, 500)
#4 [internal function]: CodeIgniter\Debug\Exceptions->exceptionHandler(Object(CodeIgniter\HTTP\Exceptions\HTTPException))
#5 {main}
thrown
#0 [internal function]: CodeIgniter\Debug\Exceptions->shutdownHandler()
#1 {main}

@jim-parry jim-parry added the bug Verified issues on the current code behavior or pull requests that will fix them label Oct 19, 2018
@jim-parry
Copy link
Contributor

This is indeed hard to follow.
If I interpret the above correctly, then we have a stack trace from a curl request exception that was not caught - so totally expected. Then it looks like the debugger tried to handle the re-thrown exception and interpret the error message as JSON, but it wasn't in JSON format.
Is this a configuration problem? a bug in Kint? Is this even a CodeIgniter bug?

@jim-parry jim-parry added investigating and removed bug Verified issues on the current code behavior or pull requests that will fix them labels Nov 16, 2018
@jim-parry
Copy link
Contributor

There is a todo item a few entries down in the issues list that suggests that CURL needs some helpers, eg. for JSON. Is this evidence of such a lack?

@natanfelles
Copy link
Contributor

CRITICAL - 2018-09-28 20:33:03 --> Undefined variable: is_install
#0 /var/www/web.ru/application/Modules/Globals/Module/func.php(209)

Is the $is_install defined?

Try:

$options = [
'base_uri' => 'you.com', // need returned error: 403 Forbidden
'timeout' => 1,
'http_errors' => false, // This avoids an exception thrown if the HTTP code is is greater than or equal to 400 
];
$client = \Config\Services::curlrequest($options);

@jim-parry
Copy link
Contributor

It looks like this is happening inside application/Modules/Globals/Module/func.php and/or application/API/v1/System/Upload.php, and I can't follow how this is a CodeIgniter bug.
Not getting further details from OP, or enough to replicate.

@pixobit
Copy link
Contributor

pixobit commented Jun 26, 2020

Managed to reproduce this issue. Was uploading an image with jquery.dm-uploader.min.js, and trying to do some image manipulation, but when I got this error:
{title: "ErrorException", type: "ErrorException", code: 500, message: "getimagesize(): Read error!",…} code: 500 file: "C:\xampp\htdocs\project\app\Controllers\File.php" line: 85 message: "getimagesize(): Read error!" title: "ErrorException" trace: [{function: "errorHandler", class: "CodeIgniter\Debug\Exceptions", type: "->",…},…] type: "ErrorException"

Then I was basically getting the same response as the OP.

Note: I managed to get the real exception by printing in in the FormatException.php file

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

6 participants