All Projects → kuria → error

kuria / error

Licence: MIT license
Makes handling and debugging PHP errors suck less

Programming Languages

PHP
23972 projects - #3 most used programming language
CSS
56736 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to error

gdbundle
Minimalist plugin manager for GDB and LLDB
Stars: ✭ 72 (+323.53%)
Mutual labels:  debugger, debug
backtrace-unity
First-class error reporting for the Unity game engine.
Stars: ✭ 99 (+482.35%)
Mutual labels:  error-handler, exception-handler
GoDebug
Go debugger (Delve) integration with Sublime Text 3
Stars: ✭ 20 (+17.65%)
Mutual labels:  debugger, debug
docker-pudb
Debug Python code within a Docker container remotely from your terminal using pudb
Stars: ✭ 18 (+5.88%)
Mutual labels:  debugger, debug
golang-debugger-book
From a debugger's view, Let's explore the computer world! How does compiler, linker and debugger coordinate with each other around the program written in specific programming language? How does a debugger work? If we develop a debugger for go programming language, we must master go type system, runtime... and some Operating System internals. OK,…
Stars: ✭ 49 (+188.24%)
Mutual labels:  debugger, debug
Logcat
Android 日志打印框架,在手机上可以直接看到 Logcat 日志啦
Stars: ✭ 189 (+1011.76%)
Mutual labels:  debugger, debug
RailLink
Compact isolated version of J-Link v9.
Stars: ✭ 69 (+305.88%)
Mutual labels:  debugger, debug
Hitchcock
The Master of Suspense 🍿
Stars: ✭ 167 (+882.35%)
Mutual labels:  debugger, debug
react-native-debug-console
A network and console debug component and modal for react native purely in JavaScript
Stars: ✭ 17 (+0%)
Mutual labels:  debugger, debug
ErrorHeroModule
💎 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
Stars: ✭ 47 (+176.47%)
Mutual labels:  error-handler, exception-handler
Acho
The Hackable Log
Stars: ✭ 189 (+1011.76%)
Mutual labels:  debugger, debug
SmartDump
SmartDump - an exception and memory dump capture utility
Stars: ✭ 17 (+0%)
Mutual labels:  debugger, debug
Ethereum Graph Debugger
Ethereum solidity graph plain debugger. To have the whole picture when debugging.
Stars: ✭ 177 (+941.18%)
Mutual labels:  debugger, debug
Pysnooper
Never use print for debugging again
Stars: ✭ 14,815 (+87047.06%)
Mutual labels:  debugger, debug
Pudb
Full-screen console debugger for Python
Stars: ✭ 2,267 (+13235.29%)
Mutual labels:  debugger, debug
hilda
LLDB wrapped and empowered by iPython's features
Stars: ✭ 99 (+482.35%)
Mutual labels:  debugger, debug
Smartdebug.js
Next-generation debugging for javascript!
Stars: ✭ 157 (+823.53%)
Mutual labels:  debugger, debug
Scyllahide
Advanced usermode anti-anti-debugger. Forked from https://bitbucket.org/NtQuery/scyllahide
Stars: ✭ 2,211 (+12905.88%)
Mutual labels:  debugger, debug
ErrorControlSystem
ErrorControlSystem is a .NET library created to automate handling .NET Windows-Base application exceptions and raise that to a sql server. This exception handler have some features as screen capturing, fetch server date time in exception occurrence time and etc.
Stars: ✭ 30 (+76.47%)
Mutual labels:  error-handler, exception-handler
PBD
🖨️🐞 Printf Based Debugger, a user-friendly C debugger
Stars: ✭ 52 (+205.88%)
Mutual labels:  debugger, debug

Error handler

Makes handling and debugging PHP errors suck less.

https://travis-ci.com/kuria/error.svg?branch=master

Web error screen in debug mode

Features

  • normal / debug mode

  • converts PHP errors (warnings, notices, etc.) into exceptions

  • respects the global error_reporting setting

  • handles uncaught exceptions and fatal errors (including parse and out-of-memory errors)

  • CLI error screen writes errors to stderr

  • web error screen renders errors for web browsers

    • normal mode shows a generic error message:
      Web error screen in normal mode
    • debug mode shows all available info:
      Web error screen in debug mode
      • file paths and line numbers
      • highlighted code previews
      • stack traces
      • argument lists
      • output buffer (can be shown as HTML too)
      • plaintext trace (for copy-paste)
  • event system that can be utilised to:

    • implement logging
    • suppress or force errors conditionally
    • change or add content to the error screens

Requirements

  • PHP 7.1+

Usage example

<?php

use Kuria\Error\ErrorHandler;

$debug = true; // true during development, false in production
error_reporting(E_ALL); // configure the error reporting

$errorHandler = new ErrorHandler();
$errorHandler->setDebug($debug);
$errorHandler->register();

// trigger an error to see the error handler in action
echo $invalidVariable;

Event system

Error handler events

Possible events emitted by the ErrorHandler class are listed in ErrorHandlerEvents:

ErrorHandlerEvents::ERROR

Emitted when a PHP errors occurs.

Arguments:

  1. Kuria\Error\Exception\ErrorException $exception
    • you may use the suppress() or force() method to suppress or force the exception, respectivelly, regardless of the error_reporting PHP setting
  2. bool $debug

ErrorHandlerEvents::EXCEPTION

Emitted when an uncaught exception or a fatal error is being handled.

Arguments:

  1. Throwable $exception
  2. bool $debug

Warning

Avoid performing memory-intensive tasks in listeners of this event if $exception is an instance of Kuria\Error\Exception\OutOfMemoryException.

ErrorHandlerEvents::FAILURE

Emitted when an uncaught exception or a fatal error could not be handled. This can happen when an exception event listener or the registered error screen throws an additional exception. Throwing another exception or causing a fatal error at this point will just kill the script.

Arguments:

  1. Throwable $exception
  2. bool $debug

Warning

Avoid performing memory-intensive tasks in listeners of this event if $exception is an instance of Kuria\Error\Exception\OutOfMemoryException.

Web error screen events

Possible events emitted by the WebErrorScreen class are listed in WebErrorScreenEvents:

WebErrorScreenEvents::RENDER

Emitted when rendering in normal mode.

Receives an array with the following keys:

  • &title: used in <title>
  • &heading: used in <h1>
  • &text: content of the default paragraph
  • &extras: custom HTML after the main section
  • exception: the exception
  • output_buffer: string|null

WebErrorScreenEvents::RENDER_DEBUG

Emitted when rendering in debug mode.

Receives an array with the following keys:

  • &title: used in <title>
  • &extras: custom HTML after the main section
  • exception: the exception
  • output_buffer: string|null

WebErrorScreenEvents::CSS

Emitted when CSS styles are being output.

Receives a single boolean value indicating debug mode.

WebErrorScreenEvents::JS

Emitted when JavaScript code is being output.

Receives a single boolean value indicating debug mode.

CLI error screen events

Possible events emitted by the CliErrorScreen class are listed in CliErrorScreenEvents:

CliErrorScreenEvents::RENDER

Emitted when rendering in normal mode.

Receives an array with the following keys:

  • &title: first line of output
  • &output: error message
  • exception: the exception
  • output_buffer: string|null

CliErrorScreenEvents::RENDER_DEBUG

Emitted when rendering in debug mode.

Receives an array with the following keys:ng keys:

  • &title: first line of output
  • &output: error message
  • exception: the exception
  • output_buffer: string|null

Event listener examples

Logging

Logging uncaught exceptions into a file:

<?php

use Kuria\Debug\Error;
use Kuria\Error\ErrorHandlerEvents;

$errorHandler->on(ErrorHandlerEvents::EXCEPTION, function (\Throwable $exception, bool $debug) {
    $logFilePath = sprintf('./errors_%s.log', $debug ? 'dev' : 'prod');

    $entry = sprintf(
        "[%s] %s: %s in file %s on line %d\n",
        date('Y-m-d H:i:s'),
        Error::getExceptionName($exception),
        $exception->getMessage(),
        $exception->getFile(),
        $exception->getLine()
    );

    file_put_contents($logFilePath, $entry, FILE_APPEND | LOCK_EX);
});

Disabling the "@" operator

This listener causes statements like echo @$invalidVariable; to throw an exception regardless of the "shut-up" operator.

<?php

use Kuria\Error\Exception\ErrorException;
use Kuria\Error\ErrorHandlerEvents;

$errorHandler->on(ErrorHandlerEvents::ERROR, function (ErrorException $exception, bool $debug) {
    $exception->force();
});

Altering the error screens

Note

Examples are for the WebErrorScreen.

Changing default labels in normal mode:

<?php

use Kuria\Error\Screen\WebErrorScreen;
use Kuria\Error\Screen\WebErrorScreenEvents;

$errorScreen = $errorHandler->getErrorScreen();

if (!$errorHandler->isDebugEnabled() && $errorScreen instanceof WebErrorScreen) {
    $errorScreen->on(WebErrorScreenEvents::RENDER, function ($event) {
        $event['heading'] = 'It is all your fault!';
        $event['text'] = 'You have broken everything and now I hate you.';
    });
}

Adding a customized section to the debug screen:

<?php

use Kuria\Error\Screen\WebErrorScreen;
use Kuria\Error\Screen\WebErrorScreenEvents;

$errorScreen = $errorHandler->getErrorScreen();

if ($errorHandler->isDebugEnabled() && $errorScreen instanceof WebErrorScreen) {
    // add custom CSS
    $errorScreen->on(WebErrorScreenEvents::CSS, function () {
        echo '#custom-group {color: #f60000;}';
    });

    // add custom HTML
    $errorScreen->on(WebErrorScreenEvents::RENDER_DEBUG, function (array $view) {
        $view['extras'] .= <<<HTML
<div id="custom-group" class="group">
 <div class="section">
     Example of a custom section
 </div>
</div>
HTML;
       });
   }
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].