aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Peugnet <33429034+vincent-peugnet@users.noreply.github.com>2020-04-29 02:00:10 +0200
committerGitHub <noreply@github.com>2020-04-29 02:00:10 +0200
commit3075127e848150da8b8d19b45325460346c415c6 (patch)
tree4b0e984fe5c75cdce4249952623b6c7f6926d78c
parent35e428c077dac7e57e6f6833562c88ae4a9867da (diff)
parent1619c194a32c1496f9015a491f5fa9dff350d47e (diff)
downloadwcms-3075127e848150da8b8d19b45325460346c415c6.tar.gz
wcms-3075127e848150da8b8d19b45325460346c415c6.zip
Merge pull request #108 from vincent-peugnet/add-whoops
Add whoops
-rw-r--r--README.md11
-rw-r--r--app/class/Config.php16
-rw-r--r--app/class/Controlleruser.php7
-rw-r--r--app/class/Media.php3
-rw-r--r--app/class/User.php3
-rw-r--r--composer.json1
-rw-r--r--composer.lock110
-rw-r--r--index.php23
8 files changed, 155 insertions, 19 deletions
diff --git a/README.md b/README.md
index 0bb744f..58de3b7 100644
--- a/README.md
+++ b/README.md
@@ -58,10 +58,10 @@ There is lot more you can by altering the `BODY`.
-Devellopement team
+Development team
------------------
-W is a project created and maintained by [Vincent Peugnet](https://github.com/vincent-peugnet), an amateur computer science enthousiast who can only code in PHP. It now includes [Nicolas Peugnet](https://github.com/n-peugnet) (his brother) as JS develloper, technical advisor and every challenges that are too complicated for Vincent.
+W is a project created and maintained by [Vincent Peugnet](https://github.com/vincent-peugnet), an amateur computer science enthousiast who can only code in PHP. It now includes [Nicolas Peugnet](https://github.com/n-peugnet) (his brother) as JS developer, technical advisor and every challenges that are too complicated for Vincent.
We can also mention [Guilhem Prévost Leygonie]() as legendary number one user and now as an issue writer too.
@@ -133,10 +133,15 @@ There are 3 different build environments that `make` can use:
The build environment can be set either for each `make` command by changing it in the `.env` file or on a per command basis by adding it at the end of the command (e.g. `make build ENV=prod`).
+PHP development
+---------------
+
+There is an error reporting debug mode using [Whoops](https://github.com/filp/whoops). It can be enabled by setting the value of `debug` in `config.json` to one of [editors supported by Whoops](https://github.com/filp/whoops/blob/master/docs/Open%20Files%20In%20An%20Editor.md).
+
JS development
--------------
-While developing the JS sources it is useful to run webpack in watch mode so that the bundles get built at each file change. To do so, use the following command:
+While developing JS code it is useful to run webpack in watch mode so that the bundles get built at each file change. To do so, use the following command:
make watch
diff --git a/app/class/Config.php b/app/class/Config.php
index 37321e4..c7d1a78 100644
--- a/app/class/Config.php
+++ b/app/class/Config.php
@@ -2,8 +2,6 @@
namespace Wcms;
-use Http\Client\Common\Plugin\RetryPlugin;
-
abstract class Config
{
protected static $pagetable = 'mystore';
@@ -35,6 +33,8 @@ abstract class Config
protected static $bookmark = [];
protected static $secretkey = null;
protected static $sentrydsn = '';
+ /** @var string|false $debug */
+ protected static $debug = false;
public const SECRET_KEY_MIN = 16;
public const SECRET_KEY_MAX = 128;
@@ -271,6 +271,11 @@ abstract class Config
return self::$sentrydsn;
}
+ public static function debug()
+ {
+ return self::$debug;
+ }
+
// __________________________________________ S E T ______________________________________
@@ -469,6 +474,13 @@ abstract class Config
}
}
+ public static function setdebug($debug)
+ {
+ if (is_string($debug)) {
+ self::$debug = $debug;
+ }
+ }
+
diff --git a/app/class/Controlleruser.php b/app/class/Controlleruser.php
index 53cf9b9..0345434 100644
--- a/app/class/Controlleruser.php
+++ b/app/class/Controlleruser.php
@@ -2,8 +2,7 @@
namespace Wcms;
-use Exception;
-use Throwable;
+use RuntimeException;
class Controlleruser extends Controller
{
@@ -38,7 +37,7 @@ class Controlleruser extends Controller
$user = $this->usermanager->get($this->user);
try {
$user->hydrateexception($_POST);
- } catch (\Throwable $th) {
+ } catch (RuntimeException $th) {
Model::sendflashmessage('There was a problem when updating preference : ' . $th->getMessage(), 'error');
}
if ($_POST['passwordhash']) {
@@ -63,7 +62,7 @@ class Controlleruser extends Controller
$user = $usermanager->get($_POST['user']);
$user->addbookmark($bookmark);
$usermanager->add($user);
- } catch (Throwable $th) {
+ } catch (RuntimeException $th) {
Logger::errorex($th, true);
Model::sendflashmessage('Error while creating bookmark : ' . $th->getMessage(), 'error');
}
diff --git a/app/class/Media.php b/app/class/Media.php
index 099d4f8..3a34a04 100644
--- a/app/class/Media.php
+++ b/app/class/Media.php
@@ -267,7 +267,8 @@ class Media extends Item
$timestamp = filemtime($this->getfulldir());
try {
$this->date = new DateTimeImmutable("@$timestamp");
- } catch (\Throwable $th) {
+ } catch (Exception $e) {
+ Logger::warningex($e);
$this->date = new DateTimeImmutable();
}
}
diff --git a/app/class/User.php b/app/class/User.php
index b2b6193..efd89ae 100644
--- a/app/class/User.php
+++ b/app/class/User.php
@@ -4,6 +4,7 @@ namespace Wcms;
use DateTimeImmutable;
use DateTimeZone;
+use RuntimeException;
class User extends Item
{
@@ -203,7 +204,7 @@ class User extends Item
function ($datas) {
try {
return new Bookmark($datas);
- } catch (\Throwable $th) {
+ } catch (RuntimeException $e) {
return false;
}
},
diff --git a/composer.json b/composer.json
index 072f4e2..95a2d94 100644
--- a/composer.json
+++ b/composer.json
@@ -9,6 +9,7 @@
"michelf/php-markdown": "^1.8"
},
"require-dev": {
+ "filp/whoops": "^2.7",
"pepakriz/phpstan-exception-rules": "^0.10.1",
"phpstan/phpstan": "^0.12.19",
"phpstan/phpstan-phpunit": "^0.12.8",
diff --git a/composer.lock b/composer.lock
index ffc81ad..5606478 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
- "content-hash": "fa8ab175273737ddd7b8aed0ce7bc82f",
+ "content-hash": "6da5a2cb510d9953dfe07df3411f9cd9",
"packages": [
{
"name": "altorouter/altorouter",
@@ -332,6 +332,67 @@
"time": "2019-10-21T16:45:58+00:00"
},
{
+ "name": "filp/whoops",
+ "version": "2.7.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/filp/whoops.git",
+ "reference": "fff6f1e4f36be0e0d0b84d66b413d9dcb0c49130"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/filp/whoops/zipball/fff6f1e4f36be0e0d0b84d66b413d9dcb0c49130",
+ "reference": "fff6f1e4f36be0e0d0b84d66b413d9dcb0c49130",
+ "shasum": ""
+ },
+ "require": {
+ "php": "^5.5.9 || ^7.0",
+ "psr/log": "^1.0.1"
+ },
+ "require-dev": {
+ "mockery/mockery": "^0.9 || ^1.0",
+ "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0",
+ "symfony/var-dumper": "^2.6 || ^3.0 || ^4.0 || ^5.0"
+ },
+ "suggest": {
+ "symfony/var-dumper": "Pretty print complex values better with var-dumper available",
+ "whoops/soap": "Formats errors as SOAP responses"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.6-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Whoops\\": "src/Whoops/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Filipe Dobreira",
+ "homepage": "https://github.com/filp",
+ "role": "Developer"
+ }
+ ],
+ "description": "php error handling for cool kids",
+ "homepage": "https://filp.github.io/whoops/",
+ "keywords": [
+ "error",
+ "exception",
+ "handling",
+ "library",
+ "throwable",
+ "whoops"
+ ],
+ "time": "2020-01-15T10:00:00+00:00"
+ },
+ {
"name": "guzzlehttp/promises",
"version": "v1.3.1",
"source": {
@@ -2076,6 +2137,53 @@
"time": "2016-08-06T14:39:51+00:00"
},
{
+ "name": "psr/log",
+ "version": "1.1.3",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/php-fig/log.git",
+ "reference": "0f73288fd15629204f9d42b7055f72dacbe811fc"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/php-fig/log/zipball/0f73288fd15629204f9d42b7055f72dacbe811fc",
+ "reference": "0f73288fd15629204f9d42b7055f72dacbe811fc",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.1.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Psr\\Log\\": "Psr/Log/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "PHP-FIG",
+ "homepage": "http://www.php-fig.org/"
+ }
+ ],
+ "description": "Common interface for logging libraries",
+ "homepage": "https://github.com/php-fig/log",
+ "keywords": [
+ "log",
+ "psr",
+ "psr-3"
+ ],
+ "time": "2020-03-23T09:12:05+00:00"
+ },
+ {
"name": "ralouphie/getallheaders",
"version": "3.0.3",
"source": {
diff --git a/index.php b/index.php
index 154d947..49974f7 100644
--- a/index.php
+++ b/index.php
@@ -1,21 +1,27 @@
<?php
-use Wcms\Logger;
-
session_start();
require('./vendor/autoload.php');
try {
- Logger::init('w_error.log', 2);
-} catch (Throwable $e) {
+ Wcms\Logger::init('w_error.log', 2);
+} catch (RuntimeException $e) {
die('Unable to init logs: ' . $e->getMessage());
}
$app = new Wcms\Application();
$app->wakeup();
+if (class_exists('Whoops\Run') && !empty(Wcms\Config::debug())) {
+ $whoops = new \Whoops\Run();
+ $handler = new \Whoops\Handler\PrettyPageHandler();
+ $handler->setEditor(\Wcms\Config::debug());
+ $whoops->pushHandler($handler);
+ $whoops->register();
+}
+
if (isreportingerrors()) {
Sentry\init([
'dsn' => Wcms\Config::sentrydsn(),
@@ -33,11 +39,14 @@ if (isreportingerrors()) {
try {
$matchoper = new Wcms\Routes();
$matchoper->match();
-} catch (Exception $e) {
+} catch (Throwable $e) {
if (isreportingerrors()) {
Sentry\captureException($e);
}
- Logger::errorex($e, true);
+ Wcms\Logger::errorex($e, true);
http_response_code(500);
- echo '<h1>⚠ Woops ! There is a little problem : </h1>', $e->getMessage(), "\n";
+ if (isset($whoops)) {
+ $whoops->handleException($e);
+ }
+ echo '<h1>⚠ Whoops ! There is a little problem : </h1>', $e->getMessage(), "\n";
}