Skip to content

Commit c395102

Browse files
refactor(agent): improve drupal hook map error logging (#1101)
Addresses #1099 Enhances #1100
1 parent b6f1b20 commit c395102

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

agent/fw_drupal8.c

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -605,14 +605,23 @@ NR_PHP_WRAPPER_END
605605
#endif // OAPI
606606

607607
static bool nr_is_invalid_key_val_arr(nr_php_string_hash_key_t* key,
608-
zval* val) {
609-
if (NULL == key || 0 == ZEND_STRING_LEN(key)
610-
|| 0 == nr_php_is_zval_valid_array(val)
608+
zval* val,
609+
const char* key_ident) {
610+
if (NULL == key || 0 == ZEND_STRING_LEN(key)) {
611+
nrl_warning(NRL_FRAMEWORK, "hookImplementationsMap[%s]: invalid key",
612+
key_ident);
613+
return true;
614+
}
615+
616+
if (0 == nr_php_is_zval_valid_array(val)
611617
|| 0 == zend_hash_num_elements(Z_ARRVAL_P(val))) {
618+
nrl_warning(NRL_FRAMEWORK,
619+
"hookImplementationsMap[%s]: invalid value for key '%s'",
620+
key_ident, NRSAFESTR(ZEND_STRING_VALUE(key)));
612621
return true;
613-
} else {
614-
return false;
615622
}
623+
624+
return false;
616625
}
617626

618627
/*
@@ -646,25 +655,27 @@ static bool nr_drupal_hook_attribute_instrument(zval* module_handler) {
646655

647656
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(hook_implementation_map), hook_key,
648657
hook_val) {
649-
if (nr_is_invalid_key_val_arr(hook_key, hook_val)) {
650-
nrl_warning(NRL_FRAMEWORK,
651-
"hookImplementationsMap[hook]: invalid key or value");
658+
if (nr_is_invalid_key_val_arr(hook_key, hook_val, "hook")) {
652659
return false;
653660
}
654661

655662
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(hook_val), class_key, class_val) {
656-
if (nr_is_invalid_key_val_arr(class_key, class_val)) {
657-
nrl_warning(NRL_FRAMEWORK,
658-
"hookImplementationsMap[class]: invalid key or value");
663+
if (nr_is_invalid_key_val_arr(class_key, class_val, "class")) {
659664
return false;
660665
}
661666

662667
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(class_val), method_key,
663668
module_val) {
664-
if (NULL == method_key
665-
|| 0 == nr_php_is_zval_valid_string(module_val)) {
669+
if (NULL == method_key) {
666670
nrl_warning(NRL_FRAMEWORK,
667-
"hookImplementationsMap[method]: invalid key or value");
671+
"hookImplementationsMap[method]: invalid key");
672+
return false;
673+
}
674+
if (0 == nr_php_is_zval_valid_string(module_val)) {
675+
nrl_warning(
676+
NRL_FRAMEWORK,
677+
"hookImplementationsMap[method]: invalid value for key '%s'",
678+
NRSAFESTR(ZEND_STRING_VALUE(method_key)));
668679
return false;
669680
}
670681

0 commit comments

Comments
 (0)