Skip to content

Commit c64fe80

Browse files
author
David Otis
committed
Refactor exception handling in core/Config
1 parent 8a2dc26 commit c64fe80

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

system/core/Config.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public function __construct()
115115
* @param bool $use_sections Whether configuration values should be loaded into their own section
116116
* @param bool $fail_gracefully Whether to just return FALSE or display an error message
117117
* @return bool TRUE if the file was loaded correctly or FALSE on failure
118+
* @throws RuntimeException Throws a runtime exception if the config file can't be found or doesn't have a valid configuration array.
118119
*/
119120
public function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
120121
{
@@ -145,7 +146,7 @@ public function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE
145146
return FALSE;
146147
}
147148

148-
show_error('Your '.$file_path.' file does not appear to contain a valid configuration array.');
149+
throw new RuntimeException('Your '.$file_path.' file does not appear to contain a valid configuration array.');
149150
}
150151

151152
if ($use_sections === TRUE)
@@ -175,7 +176,7 @@ public function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE
175176
return FALSE;
176177
}
177178

178-
show_error('The configuration file '.$file.'.php does not exist.');
179+
throw new RuntimeException('The configuration file '.$file.'.php does not exist.');
179180
}
180181

181182
// --------------------------------------------------------------------

tests/codeigniter/core/Config_test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public function test_load()
226226
// Test regular fail of invalid file
227227
$this->setExpectedException(
228228
'RuntimeException',
229-
'CI Error: Your '.$this->ci_vfs_path('config/'.$file.'.php', APPPATH).
229+
'Your '.$this->ci_vfs_path('config/'.$file.'.php', APPPATH).
230230
' file does not appear to contain a valid configuration array.'
231231
);
232232
$this->assertNull($this->config->load($file));
@@ -243,7 +243,7 @@ public function test_load_nonexistent()
243243
$file = 'absentia';
244244
$this->setExpectedException(
245245
'RuntimeException',
246-
'CI Error: The configuration file '.$file.'.php does not exist.'
246+
'The configuration file '.$file.'.php does not exist.'
247247
);
248248
$this->assertNull($this->config->load($file));
249249
}

0 commit comments

Comments
 (0)