Skip to content

Commit

Permalink
Promote warnings to exceptions in ext/pspell
Browse files Browse the repository at this point in the history
Closes GH-6010
  • Loading branch information
kocsismate committed Aug 18, 2020
1 parent cf3fb14 commit bf9ef51
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 4 additions & 4 deletions ext/pspell/pspell.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,17 @@ static void php_pspell_close_config(zend_resource *rsrc)
#define PSPELL_FETCH_CONFIG do { \
zval *res = zend_hash_index_find(&EG(regular_list), conf); \
if (res == NULL || Z_RES_P(res)->type != le_pspell_config) { \
php_error_docref(NULL, E_WARNING, ZEND_LONG_FMT " is not a PSPELL config index", conf); \
RETURN_FALSE; \
zend_throw_error(NULL, "%s(): " ZEND_LONG_FMT " is not a PSPELL config index", get_active_function_name(), conf); \
RETURN_THROWS(); \
} \
config = (PspellConfig *)Z_RES_P(res)->ptr; \
} while (0)

#define PSPELL_FETCH_MANAGER do { \
zval *res = zend_hash_index_find(&EG(regular_list), scin); \
if (res == NULL || Z_RES_P(res)->type != le_pspell) { \
php_error_docref(NULL, E_WARNING, ZEND_LONG_FMT " is not a PSPELL result index", scin); \
RETURN_FALSE; \
zend_throw_error(NULL, "%s(): " ZEND_LONG_FMT " is not a PSPELL result index", get_active_function_name(), scin); \
RETURN_THROWS(); \
} \
manager = (PspellManager *)Z_RES_P(res)->ptr; \
} while (0);
Expand Down
10 changes: 6 additions & 4 deletions ext/pspell/tests/003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ $p = pspell_new_config($cfg);
var_dump(pspell_check($p, 'yy'));

$p2 = pspell_new_config($cfg2);
var_dump(pspell_check($p2, 'yy'));
try {
pspell_check($p2, 'yy');
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}

echo "---\n";
var_dump(pspell_config_ignore($cfg, 2));
Expand All @@ -30,9 +34,7 @@ var_dump(pspell_config_ignore($cfg, PHP_INT_MAX));
bool(false)

Warning: pspell_new_config(): PSPELL couldn't open the dictionary. reason: The encoding "b0rked" is not known. This could also mean that the file "%sb0rked.%s" could not be opened for reading or does not exist. in %s003.php on line 9

Warning: pspell_check(): 0 is not a PSPELL result index in %s003.php on line 10
bool(false)
pspell_check(): 0 is not a PSPELL result index
---
bool(true)
bool(true)
Expand Down

0 comments on commit bf9ef51

Please sign in to comment.