PHP errors for cool kids

Overview

whoops

PHP errors for cool kids

Total Downloads Latest Version Build Status on newer versions Build Status on older versions Scrutinizer Quality Score Code Coverage


Whoops!

whoops is an error handler framework for PHP. Out-of-the-box, it provides a pretty error interface that helps you debug your web projects, but at heart it's a simple yet powerful stacked error handling system.

Features

  • Flexible, stack-based error handling
  • Stand-alone library with (currently) no required dependencies
  • Simple API for dealing with exceptions, trace frames & their data
  • Includes a pretty rad error page for your webapp projects
  • Includes the ability to open referenced files directly in your editor and IDE
  • Includes handlers for different response formats (JSON, XML, SOAP)
  • Easy to extend and integrate with existing libraries
  • Clean, well-structured & tested code-base

Sponsors

Blackfire.io

Installing

If you use Laravel 4, Laravel 5.5+ or Mezzio, you already have Whoops. There are also community-provided instructions on how to integrate Whoops into Silex 1, Silex 2, Phalcon, Laravel 3, Laravel 5, CakePHP 3, CakePHP 4, Zend 2, Zend 3, Yii 1, FuelPHP, Slim, Pimple, Laminas, or any framework consuming StackPHP middlewares or PSR-7 middlewares.

If you are not using any of these frameworks, here's a very simple way to install:

  1. Use Composer to install Whoops into your project:

    composer require filp/whoops
  2. Register the pretty handler in your code:

    $whoops = new \Whoops\Run;
    $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
    $whoops->register();

For more options, have a look at the example files in examples/ to get a feel for how things work. Also take a look at the API Documentation and the list of available handlers below.

You may also want to override some system calls Whoops does. To do that, extend Whoops\Util\SystemFacade, override functions that you want and pass it as the argument to the Run constructor.

You may also collect the HTML generated to process it yourself:

$whoops = new \Whoops\Run;
$whoops->allowQuit(false);
$whoops->writeToOutput(false);
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
$html = $whoops->handleException($e);

Available Handlers

whoops currently ships with the following built-in handlers, available in the Whoops\Handler namespace:

  • PrettyPageHandler - Shows a pretty error page when something goes pants-up
  • PlainTextHandler - Outputs plain text message for use in CLI applications
  • CallbackHandler - Wraps a closure or other callable as a handler. You do not need to use this handler explicitly, whoops will automatically wrap any closure or callable you pass to Whoops\Run::pushHandler
  • JsonResponseHandler - Captures exceptions and returns information on them as a JSON string. Can be used to, for example, play nice with AJAX requests.
  • XmlResponseHandler - Captures exceptions and returns information on them as a XML string. Can be used to, for example, play nice with AJAX requests.

You can also use pluggable handlers, such as SOAP handler.

Authors

This library was primarily developed by Filipe Dobreira, and is currently maintained by Denis Sokolov. A lot of awesome fixes and enhancements were also sent in by various contributors. Special thanks to Graham Campbell and Markus Staab for continuous participation.

This software includes Prettify, licensed under Apache License 2.0. It is bundled only as a performance optimization.

Issues
  • Refresh PrettyPageHandler default style

    Refresh PrettyPageHandler default style

    WORK IN PROGRESS - Not ready to merge just yet!

    Scroll to the comments to see the latest versions of the design

    This PR makes a series of changes to default stylesheet for PrettyPageHandler shipped with whoops. The goal is to refresh/modernize it a bit, have it fit larger displays better, and possibly (not yet implemented) add basic mobile support.

    Here's how it looks right now:

    screen shot 2015-06-06 at 5 29 19 pm

    NOTE: While it does seem like a lot of wasted space in some parts, the goal was to improve readability, and that space will collapse on smaller displays, using media queries.

    @denis-sokolov @GrahamCampbell Would love your input - I haven't used whoops in a while, so it'd be good to see if you guys like the direction and think I'm hitting the right targets.

    Cheers!

    opened by filp 46
  • PHP7 and EngineException handling

    PHP7 and EngineException handling

    PHP7 introduces a few new classes related to Exception (RFC). BaseException is created as a parent of Exception, and EngineException is created as a child of BaseException. As a result, the exception handler may receive objects that do not match Exception (EngineException is not an instance of Exception).

    If we were to aim for PHP 7 compatibility only, I'd suggest changing all typehints in Whoops to BaseException, to allow for both Exceptions and EngineExceptions to be passed throughout.

    If we were to aim for PHP 5 and PHP 7 compatibility, as suggested by @LawnGnome, we would need to get rid of the type hint in the exception handler (Run::handleException). We would also need to remove all other typehints for Exception, as they would also need to handle both Exception and EngineException.

    I'm opening this pull request to start discussion, I don't intend for the changes within to be merged without further refinement (still working on a unit test to test catching EngineException).

    opened by adduc 42
  • Uncaught Whoops\Exception\ErrorException: Undefined index: _SERVER

    Uncaught Whoops\Exception\ErrorException: Undefined index: _SERVER

    Anytime my application throws an error (undefined variable or function, on exceptions etc), Whoops PrettyPageHandler shows me a pretty page (like it should) but the error is always the same. It's in the PrettyPageHandler itself.

    Uncaught Whoops\Exception\ErrorException: Undefined index: _SERVER in /var/.../vendor/filp/whoops/src/Whoops/Handler/PrettyPageHandler.php:666 Stack trace: #0 /var/.../vendor/filp/whoops/src/Whoops/Handler/PrettyPageHandler.php(666): Whoops\Run->handleError(8, 'Undefined index...', '/var/www/enstar...', 666, Array) #1 /var/.../vendor/filp/whoops/src/Whoops/Handler/PrettyPageHandler.php(242): Whoops\Handler\PrettyPageHandler->masked('_SERVER') #2

    The error occurs on row 666 (of course :)) in the PrettyPageHandler class:

        private function masked($superGlobalName) {
            $blacklisted = $this->blacklist[$superGlobalName];
            $values = $GLOBALS[$superGlobalName];     <--- /// Row 666, where it breaks
     
            foreach($blacklisted as $key) {
                if (isset($values[$key])) {
                    $values[$key] = str_repeat('*', strlen($values[$key]));
                }
            }
            return $values;
        }
    

    This error happens in both version 2.1.6 and 2.1.7. It looks like the new blacklist feature was added in 2.1.6 and is the root of the problem.

    I'm running PHP 7.1.1 on Ubuntu

    opened by magnus-eriksson 28
  • Offline jQuery / Zepto

    Offline jQuery / Zepto

    Fixes #93.

    This PR bundles ZeptoJS (a smaller, less backwards-compatible version of jQuery) inline, so that the stack works offline, too. Much easier to do than writing all of this in pure JavaScript (yuck).

    While I was at it, I also fixed (I hope?) the scroll-to-top feature, that was trying to use a string value and only not taking padding etc. into account.

    The syntax highlighter will not work offline, but that isn't a crucial feature, so I don't care.

    opened by franzliedke 26
  • Hide Certain PHP files or code segments with keywords.

    Hide Certain PHP files or code segments with keywords.

    I started using Whoops! and noticed pretty quickly that the stack traces went right back to my bootstrap page. On the bootstrap page, just slightly above the function call was the mysql password......... Ok I think you can see how this could go. My suggestion would be to blank out lines that have the keyword "pass" or "password" .. Just as a sanity check. Maybe have a keyword that could be in code comments that would blank out the code display altogether. /* WHOOPSBLOCK */ Also have the ability to blank out or omit entire php files from the the stack trace.

    Now you may already have this functionality... Problem is, I couldn't find it in the README.... Thanks!

    opened by canadiannomad 25
  • Link to Google / StackOverflow

    Link to Google / StackOverflow

    I just spent about 25 minutes working out where to put some code for a PR and ended up doing it on an old version. So, to save me trying to work it out (its 12:45am already), would you consider doing this for me?

                <?php /* Link to help resources */ ?>
                <div class="data-table-container" id="handlers">
                  <label>Help</label>
                  <ul>
                    <li><a href="http://google.com/search?q=<?php echo urlencode(implode('\\', $v->name).' '.$v->message) ?>">Google</a></li>
                    <li><a href="http://stackoverflow.com/search?q=<?php echo urlencode(implode('\\', $v->name).' '.$v->message) ?>">Stack Overflow</a></li>
                  </ul>
                </div>
    

    The general idea is to shove some links in to various search pages, to try and limit how many people copy and paste error messages directly into forums asking for help. If there is a "Help" section then people might start using the internet to answer their questions, and the whole world gets that little bit more bearable.

    opened by philsturgeon 25
  • BC Break in 2.4.0

    BC Break in 2.4.0

    I believe version 2.4.0 contains BC Break (because of https://github.com/filp/whoops/pull/630) in method:

    https://github.com/filp/whoops/blob/cde50e6720a39fdacb240159d3eea6865d51fd96/src/Whoops/Run.php#L130-L133

    Because internal storage has been changed from stack to queue (reversed order) this method return now reversed order of handler than in version prior to 2.4.0.

    Code to reproduce:

    $run->pushHandler($handler1);
    $run->pushHandler($handler2);
    
    assertSame([$handler1, $handler2], $run->getHanlders());
    

    Works on <2.4.0 and fails on 2.4.0+.

    /cc @tflori

    opened by michalbundyra 23
  • PHP 5.5 minimum requirement?

    PHP 5.5 minimum requirement?

    Is there a real reason why you bumped minimum PHP requirement to 5.5.9 instead of 5.4.0?

    I'm asking this because of I have a project where I'm using whoops and I need to support everything between 5.4 and 7.0. I can eventually raise the PHP minimum, but not without prior notice to the users.

    opened by mahagr 23
  • added ZeroClipboard integration

    added ZeroClipboard integration

    this pr adds integration with zero clipboard[1].

    clicking the button copies the exception and its backtrace into the clipboard to ease e.g. creation of bugtracking tickets etc.

    clip

    clicking the button copies the following plain text into the clipboard:

    Exception thrown with message "wah"
    
    Stacktrace:
    #4 Exception in XXXXX/app/www/controllers/IndexController.php:12
    #3 IndexController:index in XXX/lib/ActionController.php:778
    #2 ActionController:invokeAction in XXX/lib/ActionController.php:290
    #1 ActionController:render in XXXCore.php:65
    #0 include_once in XXX/public/www/index.php:29
    

    Since this feature requires a external ZeroClipboard.swf file, I adjusted the path to load it from the cloudfare CDN. The "Copy to Clipboard" button only appears when the external resource could be loaded properly.

    [1] https://github.com/zeroclipboard/zeroclipboard

    opened by staabm 22
  • Issue 367 svg

    Issue 367 svg

    opened by prisis 21
  • xdebug.file_link_format template by default without xdebug extension loaded

    xdebug.file_link_format template by default without xdebug extension loaded

    When xdebug is not enabled but the propertie xdebug.file_link_format exists, set xdebug by default as editor based on Symfony HtmlErrorRenderer

    https://github.com/symfony/error-handler/blob/0e6768b8c0dcef26df087df2bbbaa143867a59b2/ErrorRenderer/HtmlErrorRenderer.php#L61-L63

    opened by erikn69 0
  • Idea: Cookbook

    Idea: Cookbook

    There don't seem to be any practical examples of how to use the functionality of Whoops in the documentation. I've had to spend a significant amount of time making sense of the inspector/frame functionality, and I'm still struggling in figuring out how to do something practical with it.

    opened by jbnv 1
  • Running php from cli, Whoop does not show the file, where first output or headers sent.

    Running php from cli, Whoop does not show the file, where first output or headers sent.

    Reproduce:

    Tested PHP version: 7.2.19, 7.3.6, Whoops version: 2.3.1

    I recently missed "space" into some configuration file. With Whoops turned off, php output shows:

    php -r "include 'index.php';"
    PHP Warning:  Cannot modify header information - headers already sent by (output started at /home/www/public_html/config/dev/database.php:1)
    

    But with Whoops enabled, I have no idea, which file to blame:

    PHP Fatal error:  Uncaught Whoops\Exception\ErrorException: session_set_save_handler(): Cannot change save handler when headers already sent in /home/www/public_html/system/library/session.php:19
    Stack trace:
    #0 [internal function]: Whoops\Run->handleError(2, 'session_set_sav...', '/home/www/publi...', 19, Array)
    #1 /home/www/public_html/system/library/session.php(19): session_set_save_handler(Object(Session\Native))
    #2 /home/www/public_html/system/framework.php(85): Session->__construct()
    #3 /home/www/public_html/vendor/laravel/framework/src/Illuminate/Container/Container.php(764): {closure}(Object(Registry), Array)
    #4 /home/www/public_html/vendor/laravel/framework/src/Illuminate/Container/Container.php(646): Illuminate\Container\Container->build(Object(Closure))
    #5 /home/www/public_html/vendor/laravel/framework/src/Illuminate/Container/Container.php(601): Illuminate\Container\Container->resolve('session', Array)
    #6 /home/www/publi in /home/www/public_html/system/library/session.php on line 19
    Whoops\Exception\ErrorException: Uncaught Whoops\Exception\ErrorException: session_set_save_handler(): Cannot change save handler when headers already sent in /home/www/public_html/system/library/session.php:19
    Stack trace:
    #0 [internal function]: Whoops\Run->handleError(2, 'session_set_sav...', '/home/www/publi...', 19, Array)
    #1 /home/www/public_html/system/library/session.php(19): session_set_save_handler(Object(Session\Native))
    #2 /home/www/public_html/system/framework.php(85): Session->__construct()
    #3 /home/www/public_html/vendor/laravel/framework/src/Illuminate/Container/Container.php(764): {closure}(Object(Registry), Array)
    #4 /home/www/public_html/vendor/laravel/framework/src/Illuminate/Container/Container.php(646): Illuminate\Container\Container->build(Object(Closure))
    #5 /home/www/public_html/vendor/laravel/framework/src/Illuminate/Container/Container.php(601): Illuminate\Container\Container->resolve('session', Array)
    #6 /home/www/publi in file /home/www/public_html/system/library/session.php on line 19
    Stack trace:
      1. Whoops\Exception\ErrorException->() /home/www/public_html/system/library/session.php:19
    

    Is there something to be done?

    opened by arnisjuraga 6
  • drop HHVM and PHP5.x support

    drop HHVM and PHP5.x support

    HHVM is used nearly anywhere and since php7 is a thing also doesnt has a real use-case anymore.

    it was a great project to boost zend-php though.

    we should drop hhvm and php5.x support and cleanup the code-base from hhvm workarounds (and drop hhvm ci).

    do you guys agree? If so, I can provide a PR.

    opened by staabm 14
PHP errors for cool kids

whoops PHP errors for cool kids whoops is an error handler framework for PHP. Out-of-the-box, it provides a pretty error interface that helps you debu

Filipe Dobreira 12.4k Jun 18, 2021
Handle PHP errors, dump variables, execute PHP code remotely in Google Chrome

PHP Console server library PHP Console allows you to handle PHP errors & exceptions, dump variables, execute PHP code remotely and many other things u

Sergey 1.3k Jun 5, 2021
PHP APM (Alternative PHP Monitor)

APM (Alternative PHP Monitor) APM (Alternative PHP Monitor) is a monitoring extension enabling native Application Performance Management (APM) for PHP

Patrick Allaert 305 May 25, 2021
A Laravel Package to integrate Nette Tracy Debugger

Nette Tracy for Laravel 5 Better Laravel Exception Handler Features Visualization of errors and exceptions Debugger Bar (ajax support @v1.5.6) Excepti

Recca Tsai 385 May 25, 2021
A beautiful error page for Laravel apps

Ignition: a beautiful error page for Laravel apps Ignition is a beautiful and customizable error page for Laravel applications running on Laravel 5.5

Facade 1.8k Jun 11, 2021
Clockwork - php dev tools in your browser - server-side component

Clockwork is a development tool for PHP available right in your browser. Clockwork gives you an insight into your application runtime - including requ

its 3.6k Jun 13, 2021
Dontbug is a reverse debugger for PHP

Dontbug Debugger Dontbug is a reverse debugger (aka time travel debugger) for PHP. It allows you to record the execution of PHP scripts (in command li

Sidharth Kshatriya 711 May 4, 2021
Low-overhead sampling profiler for PHP 7+

phpspy phpspy is a low-overhead sampling profiler for PHP. For now, it works with Linux 3.2+ x86_64 non-ZTS PHP 7.0+ with CLI, Apache, and FPM SAPIs.

Adam 1.1k Jun 10, 2021
Php Debugger to run in terminal to debug your code easily.

What is Dephpugger? Dephpugger (read depugger) is an open source lib to make a debug in php direct in terminal, without necessary configure an IDE. Th

Renato Cassino 185 Jun 17, 2021
Debug bar for PHP

PHP Debug Bar Displays a debug bar in the browser with information from php. No more var_dump() in your code! Features: Generic debug bar Easy to inte

Maxime Bouroumeau-Fuseau 3.8k Jun 12, 2021
The Interactive PHP Debugger

The interactive PHP debugger Implemented as a SAPI module, phpdbg can exert complete control over the environment without impacting the functionality

Joe Watkins 845 Jun 20, 2021
Laravel Debugbar (Integrates PHP Debug Bar)

Laravel Debugbar This is a package to integrate PHP Debug Bar with Laravel. It includes a ServiceProvider to register the debugbar and attach it to th

Barry vd. Heuvel 12.8k Jun 21, 2021
PHP Debug Console

PHP Console A web console to try your PHP code into Creating a test file or using php's interactive mode can be a bit cumbersome to try random php sni

Jordi Boggiano 512 May 24, 2021
Xdebug — Step Debugger and Debugging Aid for PHP

Xdebug Xdebug is a debugging tool for PHP. It provides step-debugging and a whole range of development aids, such as stack traces, a code profiler, fe

Xdebug 2.4k Jun 19, 2021