-
Notifications
You must be signed in to change notification settings - Fork 1
catch exceptions #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,8 +17,12 @@ trait SoftCacheTrait { | |
| * @param $output mixed | ||
| */ | ||
| public function writeMethodCache($method, array $args, $output) { | ||
| $cache_key = $this->getCacheKey($args); | ||
| $this->cache[$method][$cache_key] = $output; | ||
| try { | ||
| $cache_key = $this->getCacheKey($args); | ||
| $this->cache[$method][$cache_key] = $output; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to have one test case. Could you identify which line did throw the exception you found in the logs, and then stub it like here: https://stackoverflow.com/questions/45905183/mocking-methods-to-throw-error-phpunit |
||
| } catch (\Exception $e) { | ||
|
|
||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -27,10 +31,15 @@ public function writeMethodCache($method, array $args, $output) { | |
| * @return mixed | ||
| */ | ||
| public function readMethodCache($method, array $args) { | ||
| $cache_key = $this->getCacheKey($args); | ||
| if ($this->checkMethodCache($method, $args)) { | ||
| return $this->cache[$method][$cache_key]; | ||
| try { | ||
| $cache_key = $this->getCacheKey($args); | ||
| if ($this->checkMethodCache($method, $args)) { | ||
| return $this->cache[$method][$cache_key]; | ||
| } | ||
| } catch (\Exception $e) { | ||
| return false; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
|
|
@@ -40,11 +49,15 @@ public function readMethodCache($method, array $args) { | |
| * @return bool | ||
| */ | ||
| public function checkMethodCache($method, array $args) { | ||
| $cache_key = $this->getCacheKey($args); | ||
| if (!array_key_exists($method, $this->cache)) { | ||
| return false; | ||
| } | ||
| if (!array_key_exists($cache_key, $this->cache[$method])) { | ||
| try { | ||
| $cache_key = $this->getCacheKey($args); | ||
| if (!array_key_exists($method, $this->cache)) { | ||
| return false; | ||
| } | ||
| if (!array_key_exists($cache_key, $this->cache[$method])) { | ||
| return false; | ||
| } | ||
| } catch (\Exception $e) { | ||
| return false; | ||
| } | ||
| return true; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to have getCacheKey() having its own try/catch block and return false if exception is thrown.