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

Bug: OCI8 error and FormatException #6188

Closed
joshuadave143 opened this issue Jun 27, 2022 · 8 comments
Closed

Bug: OCI8 error and FormatException #6188

joshuadave143 opened this issue Jun 27, 2022 · 8 comments

Comments

@joshuadave143
Copy link

joshuadave143 commented Jun 27, 2022

PHP Version

8.1

CodeIgniter4 Version

4.2.0

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Windows

Which server did you use?

apache

Database

Oracle

What happened?

There is a bug on OCI8 connection.php (execute() function)

Can't return the true error, I set the wrong table name but it throws
Uncaught CodeIgniter\Format\Exceptions\FormatException: Failed to parse json string, error: "Type is not supported". in vendor\codeigniter4\framework\system\Format\JSONFormatter.php:41

when I comment on this code
throw $e;
connection.php line 210

it outputs the correct error

sorry for my bad English

Steps to Reproduce

Connect to oracle database

try to miss spell the table name

Expected Output

<br />
<b>Fatal error</b>:  Uncaught CodeIgniter\Format\Exceptions\FormatException: Failed to parse json string, error: &quot;Type is not supported&quot;. in C:\xampp\htdocs\ccms_project\app\microservice\emailer\vendor\codeigniter4\framework\system\Format\JSONFormatter.php:41
Stack trace:
#0 C:\xampp\htdocs\ccms_project\app\microservice\emailer\vendor\codeigniter4\framework\system\Format\JSONFormatter.php(41): CodeIgniter\Format\Exceptions\FormatException::forInvalidJSON('Type is not sup...')
#1 C:\xampp\htdocs\ccms_project\app\microservice\emailer\vendor\codeigniter4\framework\system\API\ResponseTrait.php(341): CodeIgniter\Format\JSONFormatter-&gt;format(Array)
#2 C:\xampp\htdocs\ccms_project\app\microservice\emailer\vendor\codeigniter4\framework\system\API\ResponseTrait.php(99): CodeIgniter\Debug\Exceptions-&gt;format(Array)
#3 C:\xampp\htdocs\ccms_project\app\microservice\emailer\vendor\codeigniter4\framework\system\Debug\Exceptions.php(120): CodeIgniter\Debug\Exceptions-&gt;respond(Array, 500)
#4 [internal function]: CodeIgniter\Debug\Exceptions-&gt;exceptionHandler(Object(ErrorException))
#5 {main}
  thrown in <b>C:\xampp\htdocs\ccms_project\app\microservice\emailer\vendor\codeigniter4\framework\system\Format\JSONFormatter.php</b> on line <b>41</b><br />
{
    "title": "ErrorException",
    "type": "ErrorException",
    "code": 500,
    "message": "Uncaught CodeIgniter\\Format\\Exceptions\\FormatException: Failed to parse json string, error: \"Type is not supported\". in C:\\xampp\\htdocs\\ccms_project\\app\\microservice\\emailer\\vendor\\codeigniter4\\framework\\system\\Format\\JSONFormatter.php:41\nStack trace:\n#0 C:\\xampp\\htdocs\\ccms_project\\app\\microservice\\emailer\\vendor\\codeigniter4\\framework\\system\\Format\\JSONFormatter.php(41): CodeIgniter\\Format\\Exceptions\\FormatException::forInvalidJSON('Type is not sup...')\n#1 C:\\xampp\\htdocs\\ccms_project\\app\\microservice\\emailer\\vendor\\codeigniter4\\framework\\system\\API\\ResponseTrait.php(341): CodeIgniter\\Format\\JSONFormatter->format(Array)\n#2 C:\\xampp\\htdocs\\ccms_project\\app\\microservice\\emailer\\vendor\\codeigniter4\\framework\\system\\API\\ResponseTrait.php(99): CodeIgniter\\Debug\\Exceptions->format(Array)\n#3 C:\\xampp\\htdocs\\ccms_project\\app\\microservice\\emailer\\vendor\\codeigniter4\\framework\\system\\Debug\\Exceptions.php(120): CodeIgniter\\Debug\\Exceptions->respond(Array, 500)\n#4 [internal function]: CodeIgniter\\Debug\\Exceptions->exceptionHandler(Object(ErrorException))\n#5 {main}\n  thrown",
    "file": "C:\\xampp\\htdocs\\ccms_project\\app\\microservice\\emailer\\vendor\\codeigniter4\\framework\\system\\Format\\JSONFormatter.php",
    "line": 41,
    "trace": [
        {
            "function": "shutdownHandler",
            "class": "CodeIgniter\\Debug\\Exceptions",
            "type": "->",
            "args": []
        }
    ]
}

Anything else?

No response

@joshuadave143 joshuadave143 added the bug Verified issues on the current code behavior or pull requests that will fix them label Jun 27, 2022
@kenjis
Copy link
Member

kenjis commented Jun 27, 2022

it outputs the correct error

What is the correct error? Exact error message?

@kenjis
Copy link
Member

kenjis commented Jun 27, 2022

Connect to oracle database
try to miss spell the table name

How did you connect? Sample code to reproduce the error?

@joshuadave143
Copy link
Author

it outputs the correct error

What is the correct error? Exact error message?

here is the correct error

Array
(
    [title] => ErrorException
    [type] => ErrorException
    [code] => 500
    [message] => oci_execute(): ORA-00942: table or view does not exist
    [file] => C:\xampp\htdocs\ccms_project\app\microservice\emailer\vendor\codeigniter4\framework\system\Database\OCI8\Connection.php
    [line] => 198
    [trace] => Array

and here's what I did to see that
I printed the $data on JSONFormatter.php

 public function format($data)
    {
        print_r($data);
        return;
        $config = new Format();

        $options = $config->formatterOptions['application/json'] ?? JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES;
        $options = $options | JSON_PARTIAL_OUTPUT_ON_ERROR;

        $options = ENVIRONMENT === 'production' ? $options : $options | JSON_PRETTY_PRINT;

        $result = json_encode($data, $options, 512);

        if (! in_array(json_last_error(), [JSON_ERROR_NONE, JSON_ERROR_RECURSION], true)) {
            throw FormatException::forInvalidJSON(json_last_error_msg());
        }

        return $result;
    }

and this error

<br />
<b>Fatal error</b>:  Uncaught CodeIgniter\Format\Exceptions\FormatException: Failed to parse json string, error: &quot;Type is not supported&quot;. in C:\xampp\htdocs\ccms_project\app\microservice\emailer\vendor\codeigniter4\framework\system\Format\JSONFormatter.php:43
Stack trace:
#0 C:\xampp\htdocs\ccms_project\app\microservice\emailer\vendor\codeigniter4\framework\system\Format\JSONFormatter.php(43): 

you get when you don't put a print_r

@joshuadave143
Copy link
Author

Connect to oracle database
try to miss spell the table name

How did you connect? Sample code to reproduce the error?

here is my .env

database.default.hostname = (DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.1)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=test.trans.local)))
# database.default.database =
database.default.username = user
database.default.password = pass
database.default.DBDriver = OCI8

@kenjis kenjis changed the title Bug: OCI8 Bug: OCI8 error and FormatException Jun 28, 2022
@kenjis
Copy link
Member

kenjis commented Jun 28, 2022

It seems when outputing Oracle error info as JSON, JSON encode error occurred.
You can see both errors in log file.

Do you know what data cannot be converted to JSON?

@joshuadave143
Copy link
Author

It seems when outputing Oracle error info as JSON, JSON encode error occurred. You can see both errors in log file.

Do you know what data cannot be converted to JSON?

Sorry I don't know

thank for your replay but the program suddenly runs perfect

@kenjis kenjis removed the bug Verified issues on the current code behavior or pull requests that will fix them label Jun 29, 2022
@kenjis
Copy link
Member

kenjis commented Jun 29, 2022

If you want output in JSON, it seems that if an error occurs that cannot be converted to JSON, then it is inevitable that you cannot see error output that you want.

In any case, please refer to the log file, as the error should be recorded.

@kenjis kenjis closed this as completed Jun 29, 2022
@joshuadave143
Copy link
Author

If you want output in JSON, it seems that if an error occurs that cannot be converted to JSON, then it is inevitable that you cannot see error output that you want.

In any case, please refer to the log file, as the error should be recorded.

Ok Thanks @kenjis

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