aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/config/ConfigJson.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2017-03-21 20:04:09 +0100
committerGitHub <noreply@github.com>2017-03-21 20:04:09 +0100
commit4bad4bde5a2b8dcbb00e95662e30b4694fe97266 (patch)
tree0e2b43f854ff230b744d292959429e743aa3609d /application/config/ConfigJson.php
parent5c0e68c07148014191270d7c82b800f0bdb9196e (diff)
parentc6a4c2882d89c6bcceeeccd319549611a5d1801b (diff)
downloadShaarli-4bad4bde5a2b8dcbb00e95662e30b4694fe97266.tar.gz
Shaarli-4bad4bde5a2b8dcbb00e95662e30b4694fe97266.tar.zst
Shaarli-4bad4bde5a2b8dcbb00e95662e30b4694fe97266.zip
Merge pull request #817 from ArthurHoaro/feature/json-conf-parsing
Proper error if the conf file is invalid instead of fatal error
Diffstat (limited to 'application/config/ConfigJson.php')
-rw-r--r--application/config/ConfigJson.php10
1 files changed, 8 insertions, 2 deletions
diff --git a/application/config/ConfigJson.php b/application/config/ConfigJson.php
index 30908d90..9ef2ef56 100644
--- a/application/config/ConfigJson.php
+++ b/application/config/ConfigJson.php
@@ -21,8 +21,14 @@ class ConfigJson implements ConfigIO
21 $data = str_replace(self::getPhpSuffix(), '', $data); 21 $data = str_replace(self::getPhpSuffix(), '', $data);
22 $data = json_decode($data, true); 22 $data = json_decode($data, true);
23 if ($data === null) { 23 if ($data === null) {
24 $error = json_last_error(); 24 $errorCode = json_last_error();
25 throw new \Exception('An error occurred while parsing JSON file: error code #'. $error); 25 $error = 'An error occurred while parsing JSON configuration file ('. $filepath .'): error code #';
26 $error .= $errorCode. '<br>➜ <code>' . json_last_error_msg() .'</code>';
27 if ($errorCode === JSON_ERROR_SYNTAX) {
28 $error .= '<br>Please check your JSON syntax (without PHP comment tags) using a JSON lint tool such as ';
29 $error .= '<a href="http://jsonlint.com/">jsonlint.com</a>.';
30 }
31 throw new \Exception($error);
26 } 32 }
27 return $data; 33 return $data;
28 } 34 }