Skip to content

Commit afb5dab

Browse files
authored
Merge pull request #363 from viest/dev
Feat(read): add file path in open file exception message
2 parents 8671a15 + 50014db commit afb5dab

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

include/xlswriter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ void url_writer(zend_long row, zend_long columns, xls_resource_write_t *res, zen
268268
lxw_error workbook_file(xls_resource_write_t *self);
269269

270270
lxw_datetime timestamp_to_datetime(zend_long timestamp);
271+
zend_string* char_join_to_zend_str(const char *left, const char *right);
271272
zend_string* str_pick_up(zend_string *left, const char *right, size_t len);
272273

273274
#endif

kernel/common.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,23 @@ zend_string* str_pick_up(zend_string *left, const char *right, size_t len)
5050
}
5151
/* }}} */
5252

53+
/* {{{ */
54+
zend_string* char_join_to_zend_str(const char *left, const char *right)
55+
{
56+
size_t _new_len = strlen(left) + strlen(right);
57+
58+
zend_string *str = zend_string_alloc(_new_len, 0);
59+
60+
memcpy(ZSTR_VAL(str), left, strlen(left));
61+
memcpy(ZSTR_VAL(str) + strlen(left), right, strlen(right) + 1);
62+
63+
ZSTR_VAL(str)[_new_len] = '\0';
64+
65+
return str;
66+
}
67+
68+
/* }}} */
69+
5370
/* {{{ */
5471
void call_object_method(zval *object, const char *function_name, uint32_t param_count, zval *params, zval *ret_val)
5572
{

kernel/read.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,22 @@ xlsxioreader file_open(const char *directory, const char *file_name) {
2323
strcat(path, file_name);
2424

2525
if (file_exists(path) == XLSWRITER_FALSE) {
26+
zend_string *message = char_join_to_zend_str("File not found, file path:", path);
27+
zend_throw_exception(vtiful_exception_ce, ZSTR_VAL(message), 121);
28+
29+
zend_string_free(message);
2630
efree(path);
27-
zend_throw_exception(vtiful_exception_ce, "File not found, please check the path in the config or file name", 121);
31+
2832
return NULL;
2933
}
3034

3135
if ((file = xlsxioread_open(path)) == NULL) {
36+
zend_string *message = char_join_to_zend_str("Failed to open file, file path:", path);
37+
zend_throw_exception(vtiful_exception_ce, ZSTR_VAL(message), 100);
38+
39+
zend_string_free(message);
3240
efree(path);
33-
zend_throw_exception(vtiful_exception_ce, "Failed to open file", 100);
41+
3442
return NULL;
3543
}
3644

tests/open_xlsx_file_not_found.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ try {
2121
//
2222
?>
2323
--EXPECT--
24-
string(64) "File not found, please check the path in the config or file name"
24+
string(57) "File not found, file path:./tests/tutorial_not_found.xlsx"

0 commit comments

Comments
 (0)