Git Product home page Git Product logo

samsonasik / errorheromodule Goto Github PK

View Code? Open in Web Editor NEW
50.0 6.0 6.0 1.56 MB

:gem: A Hero for your Zend Framework/Laminas, and Expressive/Mezzio application to log ( DB and Mail ) and handle php errors & exceptions during Mvc process/between request and response

License: MIT License

PHP 99.49% HTML 0.35% Twig 0.16%
error-handler zend-db logger zend doctrine zend-mail logging zend-expressive psr7 exception-handler

errorheromodule's Issues

Wrong format of timestamp

What ZF application I'm using when issue happen ?

  • ^ZF2.5
  • ^ZF3
  • Expressive 1
  • Expressive 2
  • Expressive 3

What PHP version you're using?

  • PHP 5.6
  • PHP 7.0
  • PHP 7.1
  • PHP 7.2

What ErrorHeroModule version you're using?

  • ^1.0
  • ^2.0

Expected behavior

Write logs to database.

Actual behavior

Nothing happens in database once bug has been occured.

Explanation

Method $this->getDateTimeFormat() https://github.com/samsonasik/ErrorHeroModule/blob/master/src/Handler/Formatter/Json.php#L26 return timestamp in "c" format 2004-02-12T15:19:21+00:00 . On my preset Mysql requires "Y-m-d H:i:s"

Workaround

Change type of 'date' to text

Refactor to allow more fatal error logging

Currently, some fatal error like :

Y cannot implement X - it is not an interface

still not logged. The code to reproduce is like below:

class X {}
class Y implements X { }

The fallback down of the error is on register_shutdown_function() call which when it is overlapped, it is not recorded by logging, as the code exited.

Integrating it into frameworks (zf-mvc and zf-expressive) is not as easy as imagined as it need to follow the dispatch flow.

The steps of refactor are as follow:

  1. move the display_errors check to early in process() or bootstrap event from the trait
  2. move the logging to phpErrorHandler() function
  3. "save" its flag "somewhere", and returns ( display as is ? ) Response instance.

It will require a big refactor, and I will do when I have a time โœŒ๏ธ

excluded errors are not excluded

What ZF/Expressive/Laminas/Mezzio application I'm using when issue happen ?

  • Laminas 3

What PHP version you're using?

  • PHP 8.1

What ErrorHeroModule version you're using?

  • ^5.0

What Database you're using?

  • Oracle 12

Expected behavior

I have added \E_DEPRECATED error as a value of the array 'exclude-php-errors' in the config file
so E_DEPRACATED errors should be ignored.

Actual behavior

E_DEPRECATED errors are still catched even if I have added \E_DEPRECATED error as a value of the array 'exclude-php-errors' in the config file.

Steps/Codes to reproduce the behavior

in \config\autoload\error-hero-module.global.php

        'exclude-php-errors' => [
            \E_USER_DEPRECATED,
            \E_DEPRECATED, // <--- add this
        ],

in index.php add this at the first beginning :

<?php $a = false; $a[] = 1;

execute index.php within your app in your browser.

the E_DEPRECATED error is catched by ErrorHeroModule.

Keeping ErrorHandler::class in ZE3 pipeline.php hides descriptive error messages

What ZF application I'm using when issue happen ?

  • Expressive 3

What PHP version you're using?

  • PHP 7.2

What ErrorHeroModule version you're using?

  • ^2.0

What Database you're using?

  • MySQL version 8.0.11

Expected behavior

Upon a PHP error, show a meaningful descriptive error message from PHP, pointing to the root cause of web page malfunction. i.e. Fatal error: [description ... ].

Actual behavior

Browser displays the following message:

Oops!
This is awkward.

We encountered a 500 Internal Server Error error.

There are no further clues to the error message in the Apache error log. There is nothing in Mozilla's Developer Tools. Nothing seems to get logged via the ErrorHeroModuleLogger in the database table.

Steps/Codes to reproduce the behavior

In my pipeline.php I have the following:

$app->pipe(ErrorHandler::class); //Zend\Stratigility\Middleware\ErrorHandler
$app->pipe(ErrorHeroModule\Middleware\Expressive::class);

I suspect that whatever the error is, it gets eaten up by the ErrorHandler::class and the generic message above is displayed, hiding the real error description.

Potential Solution: Removing the ErrorHandler::class from pipeline.php uncovers the descriptive error and displays the full error message from PHP that I am looking for.

Summary

It seems to me that the line of $app->pipe(ErrorHandler::class) is the culprit in covering up descriptive error messages. Removing it resolves my immediate issue and shows me the descriptive errors I was looking for. Can ErrorHandler::class be removed? Must it remain in Expressive pipeline config and if yes can I still see descriptive error messages?

Zend Test - "Test code or tested code did not (only) close its own output buffers" is thrown

What ZF application I'm using when issue happen ?

  • ^ZF2.5
  • [ * ] ^ZF3
  • Expressive 1
  • Expressive 2
  • Expressive 3

What PHP version you're using?

  • PHP 5.6
  • PHP 7.0
  • [ * ] PHP 7.1
  • PHP 7.2

What ErrorHeroModule version you're using?

  • ^1.0
  • [ * ] ^2.0

What Database you're using?

  • [ * ] MySQL version ...
  • PostgreSQL version ...
  • Other (please write DB name and version)

Expected behavior

When I test the application with zend-test (controller integration tests) I expect all the tests to run without any exceptions.

Actual behavior

It throws "Test code or tested code did not (only) close its own output buffers" by PHPUnit.

Steps/Codes to reproduce the behavior

Create a simple controller integration test using zend-test.

display_errors setting being set to 1 does not show errors in browser.

What ZF application I'm using when issue happen ?

  • Mezzio 3

What PHP version you're using?

  • PHP 7.4

What ErrorHeroModule version you're using?

  • ^2.0

What Database you're using?

  • MySQL version 8.0

Expected behavior

Show exact error message in the browser, and log the error message in the error log.

Actual behavior

No error is shown, but my application has null values when I expect values. The exact error message is not shown explicitly even though effects of the error are evident by observing that my application is not working as expected.

Steps/Codes to reproduce the behavior

When in the hero config file I set ['display-settings']['display_errors'] to 0, the exact error of the application is written into the log, which is helpful in debugging the error. But when I set ['display-settings']['display_errors'] to 1, my application does not show explicit error in the browser, and no error message is written into the log, even though it is evident that my application is affected by the (unknown/unlogged) error.

Thus I feel like there is more to ['display-settings']['display_errors'] setting than I am aware of. What happens when ['display-settings']['display_errors'] is set to 1, because I do not see the error in the browser, or any of the logs.

Looking in the ErrorHeroModule code briefly it looks like the setting being 0 turns off ErrorHeroModule handling of the error and pushes it back to MVC module. I am not sure what it means, but it may explain why error is not logged, and why I may not be getting an error message displayed in my browser.

Cannot change layout

What ZF/Expressive/Laminas/Mezzio application I'm using when issue happen ?

  • Laminas 3

What PHP version you're using?

  • PHP 7.4

What ErrorHeroModule version you're using?

  • ^3.0

What Database you're using?

  • MySQL version ...

Expected behavior

I'd like to change layout template file.

Actual behavior

When I change
'template' => [
'layout' => 'layout/layout',

To:

'template' => [
'layout' => 'layout/error',

Does not change anything and it still call layout of my application

PHP 8 throws Fatal Error in Logging.php when loading a Mezzio page via AJAX

What ZF/Expressive/Laminas/Mezzio application I'm using when issue happen ?

  • Mezzio 3

What PHP version you're using?

  • PHP 8.0

What ErrorHeroModule version you're using?

  • ^3.1

What Database you're using?

  • MySQL version 8.0

Expected behavior

no errors are thrown when loading a Mezzio page via AJAX

Actual behavior

PHP Fatal error: Uncaught TypeError: str_replace(): Argument #3 ($subject) must be of type array|string, Laminas\Diactoros\PhpInputStream given in vendor\samsonasik\error-hero-module\src\Handler\Logging.php:120
Stack trace:
#0 vendor\samsonasik\error-hero-module\src\Handler\Logging.php(120): str_replace('\r\n', '', Object(Laminas\Diactoros\PhpInputStream))
#1 vendor\samsonasik\error-hero-module\src\Handler\Logging.php(192): ErrorHeroModule\Handler\Logging->getRequestData(Object(Laminas\Psr7Bridge\Laminas\Request))
#2 vendor\samsonasik\error-hero-module\src\Handler\Logging.php(227): ErrorHeroModule\Handler\Logging->collectErrorExceptionExtraData(Array, Object(Laminas\Psr7Bridge\Laminas\Request))
#3 vendor\samsonasik\error-hero-module\src\Middleware\Mezzio.php(78): ErrorHeroModule\Handler\Logging->handleErrorException(Object(ErrorException), Object(Laminas\Psr7Bridge\Laminas\Request))
#4 vendor\samsonasik\error-hero-module\src\HeroTrait.php(107): ErrorHeroModule\Middleware\Mezzio->exceptionError(Object(ErrorException))
#5 [internal function]: ErrorHeroModule\Middleware\Mezzio->execOnShutdown()
#6 {main}
thrown in vendor\samsonasik\error-hero-module\src\Handler\Logging.php on line 120

Steps/Codes to reproduce the behavior

With PHP 8.0.3 I used AJAX loading method
My code has this: <a href="#" onclick="$('#div_id').load('/proposal/form');">Load Form</a>

Note - going to /proposal/form URL directly loads the form just fine. The error only happens when I use AJAX link to load the form.
I am not sure if the error is related to AJAX specifically, but that is what I am observing at this time.

enable/disable error-preview page

currently, the sample error preview is always enable when module installed. It needs suppott for enable/disable error-preview page, like : "enable-error-preview-page" option

Ignoring errors suppressed by @

What ZF application I'm using when issue happen ?

  • ^ZF2.5
  • [v] ^ZF3
  • Expressive 1
  • Expressive 2
  • Expressive 3

What PHP version you're using?

  • PHP 5.6
  • PHP 7.0
  • [v] PHP 7.1
  • PHP 7.2

Expected behavior

Errors suppressed by @ should be ignored.
PHP Manual:
If you have set a custom error handler function with set_error_handler() then it will still get called, but this custom error handler can (and should) call error_reporting() which will return 0 when the call that triggered the error was preceded by an @.

Actual behavior

Errors suppressed by @ are being caught.

Steps/Codes to reproduce the behavior

Try to run @mkdir('somedir') on directory that already exists.

error-hero-module downgrades from 2.16.0 to 2.3.0 when I update beberlei/assert to v3.1.0

What ZF application I'm using when issue happen ?

  • Expressive 3

What PHP version you're using?

  • PHP 7.1

What ErrorHeroModule version you're using?

  • ^2.0

What Database you're using?

  • MySQL version ...

Expected behavior

Not downgrading samsonasik/error-hero-module from 2.16.0 to 2.3.0.

Actual behavior

composer Downgrading samsonasik/error-hero-module (2.16.0 => 2.3.0)

Steps/Codes to reproduce the behavior

  1. Update beberlei/assert from v2.9.6 to v3.1.0 in composer.json file,
    while having samsonasik/error-hero-module (2.16.0)
  2. Run composer update

Mqtt enhancement

Hello,

I have developed an additional message transport via Mqtt for the ErrorHero Module.
Is a pull request welcome or do you think this is useless?

I have implemented it in the same way like the email feature.

Best regards,

Pierre

Exceptions Listeners Priority

What ZF application I'm using when issue happen ?

  • ^ZF2.5
  • ^ZF3
  • Expressive 1
  • Expressive 2
  • Expressive 3

What PHP version you're using?

  • PHP 5.6
  • PHP 7.0
  • PHP 7.1
  • PHP 7.2

Expected behavior

It would be very nice if all error listeners were attached with last possible priority to allow the exceptions to be catched by other listeners. For example ZfcRbac throws Unauthorized exception and catches it by itself. I think that error-hero-module should be attached to catch exceptions that otherwise would be probably not catched at all.

Actual behavior

It attaches listeners with default priority.

Steps/Codes to reproduce the behavior

For example, you can install ZfcRbac and all Unauthorized exceptions will be catched by error-hero-module.

Example for MQTT implementation

Dear Abdul,

could you give an example how I can intregrate a MQTT writer to the logic. Maybe in the README.md?

I would support you If you give me a hint.

Thank you

Cheers

Pierre

If the Ajax message is used, the HTTP response code shouldn't be 200

Dear samsonasik,

first thank you for your useful module.

I have just noticed something that bothered me a bit: if your module catches an error while doing an ajax call (the '$request->isXmlHttpRequest()' is a bit restricted as I would like to use it performing json calls but that's another story :) ), the ajax message set in the config is displayed as expected but with an 200 HTTP code. That's make difficult if not impossible to catch this failure at client side level.
Is there any way to change this and set a different HTTP code (500 would be the one IMO) ? And set as well a proper Content-type header (text/html at the moment which is not correct).

Regards,

Can't update my composer since weeks

Hello! I have many projects with this module and I have problems with update my packages. I have tried to create a new Laminas project but it is not still work.
Also I tried to install specific 3.1.1 version (compatible with PHP 7).

`composer require samsonasik/error-hero-module
Using version ^3.1 for samsonasik/error-hero-module
./composer.json has been updated
Running composer update samsonasik/error-hero-module
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

Problem 1
- laminas/laminas-diactoros[2.18.0, ..., 2.25.2] require php ~8.0.0 || ~8.1.0 || ~8.2.0 -> your php version (7.4.33) does not satisfy that requirement.
- Root composer.json requires samsonasik/error-hero-module ^3.1 -> satisfiable by samsonasik/error-hero-module[3.1.0, 3.1.1].
- samsonasik/error-hero-module[3.1.0, ..., 3.1.1] require laminas/laminas-diactoros ^2.0 -> satisfiable by laminas/laminas-diactoros[2.0.0, ..., 2.25.2].
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.17.0.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.14.0.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.6.0.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.4.1.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.2.2.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.2.1p2.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.2.1p1.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.2.1.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.2.0p2.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.2.0p1.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.2.0.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.1.5p2.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.1.5p1.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.1.5.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.1.4p2.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.1.4p1.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.1.4.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.1.3p2.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.1.3p1.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.1.3.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.1.2p2.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.1.2p1.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.1.2.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.1.1p2.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.1.1p1.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.1.1.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.1.0p2.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.1.0p1.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.1.0.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.0.3p2.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.0.3p1.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.0.3.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.0.2p2.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.0.2p1.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.0.2.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.0.1p2.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.0.1p1.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.0.1.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.0.0p2.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.0.0p1.
- roave/security-advisories dev-master conflicts with laminas/laminas-diactoros 2.0.0.
- roave/security-advisories is locked to version dev-master and an update of this package was not requested.

You can also try re-running composer require with an explicit version constraint, e.g. "composer require samsonasik/error-hero-module:*" to figure out if any version is installable, or "composer require samsonasik/error-hero-module:^2.1" if you know which you need.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.
`

What ZF/Expressive/Laminas/Mezzio application I'm using when issue happen ?

  • [X ] Laminas 3

What PHP version you're using?

  • [X ] PHP 7.4

What ErrorHeroModule version you're using?

  • [X ] ^3.0

What Database you're using?

  • [X ] MySQL version ...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.