From 194f2bd2a5569df997dd37bd5b6d0bab07f83f1c Mon Sep 17 00:00:00 2001 From: Hide_D Date: Mon, 9 May 2022 03:39:30 +0900 Subject: [PATCH] =?UTF-8?q?refac:=20=EC=97=90=EB=9F=AC=20=ED=95=B8?= =?UTF-8?q?=EB=93=A4=EB=A7=81=20=EB=B0=A9=EC=8B=9D=20=EB=B3=80=EA=B2=BD,?= =?UTF-8?q?=20FatalError=20=EB=8C=80=EC=9D=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- f_config/config.php | 16 +++++++++++++--- hwe/func_command.php | 4 ++-- hwe/j_msg_get_old.php | 2 +- hwe/j_msg_get_recent.php | 2 +- hwe/j_raise_event.php | 2 +- hwe/sammo/Event/Action/FinishNationBetting.php | 2 +- hwe/sammo/Scenario.php | 2 +- hwe/sammo/Scenario/GeneralBuilder.php | 4 ++-- j_updateServer.php | 2 +- src/sammo/APIHelper.php | 2 +- 10 files changed, 24 insertions(+), 14 deletions(-) diff --git a/f_config/config.php b/f_config/config.php index 99393641..6646a59f 100644 --- a/f_config/config.php +++ b/f_config/config.php @@ -49,7 +49,7 @@ function getFriendlyErrorType($type) return "{$type}"; } -function getExceptionTraceAsString($exception) +function getExceptionTraceAsString(\Throwable $exception) { //https://gist.github.com/abtris/1437966 $rtn = ""; @@ -117,7 +117,7 @@ function logError(string $err, string $errstr, string $errpath, array $trace) ]); } -function logErrorByCustomHandler(int $errno, string $errstr, string $errfile, int $errline, array $errcontext=null) +function logErrorByCustomHandler(int $errno, string $errstr, string $errfile, int $errline) { if (!(error_reporting() & $errno)) { // This error code is not included in error_reporting, so let it fall @@ -172,7 +172,17 @@ function getAPIExecutorClass($path){ throw new \InvalidArgumentException("{$path}는 올바른 API 경로가 아님"); } +function checkForFatal() +{ + $error = error_get_last(); + if ( $error["type"] == E_ERROR ){ + logErrorByCustomHandler( $error["type"], $error["message"], $error["file"], $error["line"] ); + } +} + +register_shutdown_function("\\sammo\\checkForFatal" ); + function buildAPIExecutorClass($type, string $rootPath, array $args):\sammo\BaseAPI{ $class = getAPIExecutorClass($type); return new $class($rootPath, $args); -} \ No newline at end of file +} diff --git a/hwe/func_command.php b/hwe/func_command.php index d8b6ac8c..0c89fef4 100644 --- a/hwe/func_command.php +++ b/hwe/func_command.php @@ -363,7 +363,7 @@ function setGeneralCommand(int $generalID, array $rawTurnList, string $command, 'target'=>'arg' ]; } - catch (\Exception $e){ + catch (\Throwable $e){ return [ 'result'=>false, 'reason'=>$e->getCode().$e->getMessage(), @@ -445,7 +445,7 @@ function setNationCommand(int $generalID, array $turnList, string $command, ?arr 'target'=>'arg' ]; } - catch (\Exception $e){ + catch (\Throwable $e){ return [ 'result'=>false, 'reason'=>$e->getCode().$e->getMessage(), diff --git a/hwe/j_msg_get_old.php b/hwe/j_msg_get_old.php index ec332914..b7758e7c 100644 --- a/hwe/j_msg_get_old.php +++ b/hwe/j_msg_get_old.php @@ -38,7 +38,7 @@ if(count($lastMsgGet) >= 10){ } array_shift($lastMsgGet); } - catch(\Exception $e){ + catch(\Throwable $e){ $lastMsgGet = []; } } diff --git a/hwe/j_msg_get_recent.php b/hwe/j_msg_get_recent.php index addfcc1e..eb15ff6a 100644 --- a/hwe/j_msg_get_recent.php +++ b/hwe/j_msg_get_recent.php @@ -24,7 +24,7 @@ if(count($lastMsgGet) >= 10){ } array_shift($lastMsgGet); } - catch(\Exception $e){ + catch(\Throwable $e){ $lastMsgGet = []; } } diff --git a/hwe/j_raise_event.php b/hwe/j_raise_event.php index cfa22499..8dc95b67 100644 --- a/hwe/j_raise_event.php +++ b/hwe/j_raise_event.php @@ -35,7 +35,7 @@ if($eventArgsJson !== null){ $eventArgs[] = $eventNextArgs; } } - catch(\Exception $e){ + catch(\Throwable $e){ Json::die([ 'result'=>false, 'reason'=>'arg가 올바른 json이 아닙니다' diff --git a/hwe/sammo/Event/Action/FinishNationBetting.php b/hwe/sammo/Event/Action/FinishNationBetting.php index 214fee48..581ec38f 100644 --- a/hwe/sammo/Event/Action/FinishNationBetting.php +++ b/hwe/sammo/Event/Action/FinishNationBetting.php @@ -23,7 +23,7 @@ class FinishNationBetting extends \sammo\Event\Action try { $bettingHelper = new Betting($this->bettingID); - } catch (\Exception $e) { + } catch (\Throwable $e) { return [__CLASS__, false, $e->getMessage()]; } diff --git a/hwe/sammo/Scenario.php b/hwe/sammo/Scenario.php index 48268e16..307ae5ae 100644 --- a/hwe/sammo/Scenario.php +++ b/hwe/sammo/Scenario.php @@ -392,7 +392,7 @@ class Scenario{ $text = \file_get_contents(ServConfig::getSharedIconPath('../hook/list.json?1')); $storedIcons = Json::decode($text); } - catch(\Exception $e){ + catch(\Throwable $e){ $storedIcons = []; } diff --git a/hwe/sammo/Scenario/GeneralBuilder.php b/hwe/sammo/Scenario/GeneralBuilder.php index 769eb354..461d786e 100644 --- a/hwe/sammo/Scenario/GeneralBuilder.php +++ b/hwe/sammo/Scenario/GeneralBuilder.php @@ -134,7 +134,7 @@ class GeneralBuilder{ $this->specialDomestic = SpecialityHelper::getDomesticClassByName($special); $this->specialWar = GameConst::$defaultSpecialWar; } - catch (\Exception $e){ + catch (\Throwable $e){ $this->specialDomestic = GameConst::$defaultSpecialDomestic; $this->specialWar = SpecialityHelper::getWarClassByName($special); } @@ -540,7 +540,7 @@ class GeneralBuilder{ $text = \file_get_contents(\sammo\ServConfig::getSharedIconPath('../hook/list.json?1')); $storedIcons = \sammo\Json::decode($text); } - catch(\Exception $e){ + catch(\Throwable $e){ $storedIcons = []; } diff --git a/j_updateServer.php b/j_updateServer.php index eedb8169..a0563d5b 100644 --- a/j_updateServer.php +++ b/j_updateServer.php @@ -345,7 +345,7 @@ if ($server == $baseServerName) { $imgResult = false; $imgDetail = $pullResult['reason']; } - } catch (\Exception $e) { + } catch (\Throwable $e) { $imgResult = false; $imgDetail = $e->getMessage(); } diff --git a/src/sammo/APIHelper.php b/src/sammo/APIHelper.php index 85991782..0dcbc4b4 100644 --- a/src/sammo/APIHelper.php +++ b/src/sammo/APIHelper.php @@ -15,7 +15,7 @@ class APIHelper try { $rawInput = file_get_contents('php://input'); $input = Json::decode($rawInput); - } catch (\Exception $e) { + } catch (\Throwable $e) { Json::dieWithReason($e->getMessage()); $input = null; }