PHP Classes

Corner: Implements exceptions and errors with more details

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 107 All time: 9,684 This week: 660Up
Version License PHP version Categories
corner 1.0.0MIT/X Consortium ...7Language, PHP 7
Description 

Author

This package implements exceptions and errors with more details.

It provides a trait that can be used in exceptions or error classes in a way that can provide to applications more details about the circumstances that triggered those exceptions or classes.

Currently it can return a more helpful message about the errors, get snippets of the code that called the other code of the application that triggered the error, as well get a link to get more support for the code that caused the error.

Innovation Award
PHP Programming Innovation award nominee
July 2019
Number 2
Exceptions are frequently used by applications to trigger errors about error conditions that they are not ready to handle.

Usually exceptions pass some information about the context of the conditions that triggered the error, like for instance the file of the source code where the error occurred.

This package provides a trait that goes farther by providing other useful information about the errors, like for instance snippets of the source code that triggered the error, as well a link to get more support from the developers responsible for the code.

Manuel Lemos
Picture of Scott Arciszewski
  Performance   Level  
Name: Scott Arciszewski <contact>
Classes: 37 packages by
Country: United States United States
Age: ???
All time rank: 1173170 in United States United States
Week rank: 44 Up6 in United States United States Up
Innovation award
Innovation award
Nominee: 28x

Winner: 1x

Documentation

Corner

Linux Build Status Latest Stable Version Latest Unstable Version License Downloads

PHP Exceptions and Errors designed to prevent your users from sharp corners. Inspired by Rust's helpful error messages.

  • Version 2.x: Requires PHP 7.1 or newer.
  • Version 1.x: Requires PHP 5.4 or newer.

Motivation

There are already libraries like Whoops which focus on taking existing uncaught Exceptions and giving them a user interface.

Rather than take control of your entire UI output, Corner extends the base Throwable interface and Exception/Error classes and makes them more useful even in non-UI contexts.

Corner's Extended Exception API

getHelpfulMessage()

> What exactly is going on here?

Imagine an email. Throwable::getMessage() can be likened to the subject line. In traditional exceptions, the closest thing you have to a message body is getTraceAsString().

In Corner, the "helpful message" is meant to be a full-text explanation of the problem. ASCII art diagrams (hard-coded or generated from the source code, if applicable) are permitted.

getSnippet($before = 0, $after = 0, $traceWalk = 0)

> What was the code surrounding the exception doing?

By default, this returns the line of PHP code that triggered the exception.

You can optionally pass a number of leading and trailing lines to this method to read more text from the source code file. The third argument allows you to excerpt snippets of code from within the stack trace.

The main use case for getSnippet() is to generate helpful error messages for getHelpfulMessage().

getSupportLink()

> Where can I find help?

The intent of this method is to give the developer using your project the quickest possible path to troubleshooting and solving the problem that they're most likely facing if this Exception / Error gets thrown.

If possible, link to a specific section of your project's documentation (including page anchors, if applicable) to get the developer closer to the solution to whatever problem they're encountering.


  Files folder image Files (12)  
File Role Description
Files folder imagesrc (4 files)
Files folder imagetest (3 files)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file psalm.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (12)  /  src  
File Role Description
  Accessible without login Plain text file CornerInterface.php Class Class source
  Accessible without login Plain text file CornerTrait.php Class Class source
  Accessible without login Plain text file Error.php Class Class source
  Accessible without login Plain text file Exception.php Class Class source

  Files folder image Files (12)  /  test  
File Role Description
  Accessible without login Plain text file BasicTest.php Class Class source
  Accessible without login Plain text file FooError.php Class Class source
  Accessible without login Plain text file FooException.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:107
This week:0
All time:9,684
This week:660Up