Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing error message in newrelic_record_custom_event() when pas an array as one of the attributes #722

Open
php4fan opened this issue Aug 29, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@php4fan
Copy link

php4fan commented Aug 29, 2023

Description

Consider the function newrelic_record_custom_events($name, $attributes).

If one of the elements of the $attributes array is itself an array, which is not supported, the error message is very confusing.

See details below.

Steps to Reproduce

Run this:

newrelic_record_custom_event("MyEvent", ['foo' => 123, 'bar' => [4,5,6]]);

Note that I'm passing an invalid set of attributes as the second parameter, given that the element bar is an array while only scalar attributes are supported.

Expected Behavior

I expect to get an error message something like this:

WARNING: newrelic_record_custom_event: expects parameter 2 to be an associative array where each element is a scalar; array given at key `'bar'.

I am very bad at phrasing error messages and you can phrase the message however you please, but the bare minimum amount of information that I demand is as above.
In particular:

  • that the issue is with the second argument passed to the function
  • that the elements of that array are what is expected to be scalar, while one of them was an array
  • what element was an array.

Observed Behavior

The error message actually thrown is this:

Warning: newrelic_record_custom_event(): newrelic_record_custom_event: expects parameter to be scalar, array given

which sucks because it lacks all the information mentioned above.

This message is extremely confusing because it looks very similar to PHP's native error message

function_name expects parameter N to be scalar, array given

so I'm induced to immediately inspect the two arguments that I passed to the function (and I'm already irritated that it's not telling me which one is the problematic one), and since the first one (the event name) is the one that is actually expected to be scalar, I'm thinking that I accidentally passed an array for the event name. So this is misleading me.

It took me a long while to realize that this was not PHP's native error message complaining about one of the two arguments passed to the function not being an array, but instead, the function's own error message complaining that one of the "parameters" (meaning one of the items of the $attributes array passed as a second argument) is an array. And still I need to figure out which one.

Your Environment

  • PHP 7.4
  • Debian 10
@php4fan php4fan added the bug Something isn't working label Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant