Skip to content

Make error messages more consistent #5066

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

Closed
wants to merge 4 commits into from

Conversation

kocsismate
Copy link
Member

@kocsismate kocsismate commented Jan 9, 2020

Currently, error messages aren't consistent at all across all the extensions. I'd like to improve the situation by collecting some general principles that can be followed when writing/rewriting error messages.

For a start, find below some ideas that I could come up with. Any help or addition is welcome. :)

Capitalize all the error messages

If the message starts with a function/parameter/ini setting name (or something that is not suitable for capitalization), then either use ' around them, or circumvent the issue (e.g. enclosure must be a character -> The 'enclosure' parameter must be a single character or Argument 1 must be a single character)

Use words consistently

E.g.: "cannot" or "can not", "filename" or "file name", "parameter" or "argument", "null" or "NUL".

Structure sentences consistently

E.g. Currently, we structure type error messages a lot of different ways:

  • Expects string, null, long or boolelan value for PostgreSQL '%s' (%s) (sic!)
  • Expected array value for this option
  • Array expected as options when using translate or scale
  • etc.

Instead of structuring messages all the possible ways, we should stick with similar structures.
For improving type error messages specifically, see suggestion #5.

Use user provided values more consistently

Some example formats I found: "Unable to fork [%s]", "Type '%s' not supported", Error opening file %s, "Invalid 'encoding' option - '%s'" etc. Additionally, there are many cases when we don't even mention what the invalid user-provided value was: Invalid OID specified. I think we should try to display user-provided values when possible by using a common format.

Phrase internal errors consistent to user-land errors

In my opinion, error messages coming from internal functions should be similar to what is also reported for user-land functions/methods. E.g. instead of Object or string expected, Argument 1 passed to foo() must be of the type object|string, array given could be written. (Of course, in this case, the best solution would be to change the ZPP checks in question to use union types).

Another example: instead of Requires 1 or 2 arguments, we could write something similar to the user-land error message: Too few arguments to function foo(), 0 passed and at least 1 expected

This PR only contains capitalization changes so far - without any test fixes.

@kocsismate kocsismate force-pushed the consistent-error-messages branch from c820870 to a40a4ac Compare January 9, 2020 00:26
Copy link
Member

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalization looks good mostly, but I think we should avoid it in places where the first word is a function name or similar. Those look odd to me.

@nikic
Copy link
Member

nikic commented Jan 9, 2020

Not sure if I mentioned it to you before, but we have scripts/dev/bless_tests.php to mostly automate these kind of test updates.

@kocsismate
Copy link
Member Author

kocsismate commented Jan 9, 2020

Not sure if I mentioned it to you before, but we have scripts/dev/bless_tests.php to mostly automate these kind of test updates.

Ah, not yet! Thanks!

To answer you all the review comments at once: first, I started with mass-capitalization, and during doing so, I noticed some problematic patterns for which I tried to come up with a solution. The first suggestion in the description is in line with your comments, but I'd like to only address them after we have decided about the possible directions and how far to go (e.g. in this case: to stick with lower-case, or try to circumvent the issue).

So @nikic, @cmb69, @Girgias, if you are also interested in this topic, I'd love to hear your opinion about the proposals, and if you have anything else to add to the list.

@Girgias
Copy link
Member

Girgias commented Jan 9, 2020

On the top of my head, the length error/warning messages should also be consistent, because we currently have mix usage of should/must and different ways of formulating the same thing must be non negative and must be greater or equal than 0 for example. I'm probably missing some others which I'll add when I encounter them again. :)

@kocsismate
Copy link
Member Author

Thanks for the idea, @Girgias , I agree with you.

I'll double check possible problems with capitalization + fix the tests so that this PR will be able to be merged, and I'll try to address the other suggestions in separate - and smaller - PRs afterwards.

@kocsismate kocsismate force-pushed the consistent-error-messages branch 4 times, most recently from ce1d0e4 to 82b85b4 Compare January 16, 2020 19:04
@kocsismate kocsismate force-pushed the consistent-error-messages branch from 82b85b4 to 0a3ed92 Compare January 16, 2020 19:20
@nikic
Copy link
Member

nikic commented Jan 17, 2020

AppVeyor failures look legit.

@kocsismate kocsismate force-pushed the consistent-error-messages branch from 0a3ed92 to 3dae4e6 Compare January 17, 2020 09:50
@kocsismate
Copy link
Member Author

Thanks for the heads up! To sum up the changes since the last review: I tried to remove all the problematic/questionable changes, and made the tests green.

@kocsismate kocsismate changed the title WIP: Make error messages more consistent Make error messages more consistent (step 1) Jan 17, 2020
Copy link
Member

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, some nits.

@@ -1,5 +1,5 @@
--TEST--
Testing dynamic call with invalid value for method name
Testing dynamic call with Invalid value for method name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spurious change

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops.

@@ -424,7 +424,7 @@ PHP_FUNCTION(oci_lob_read)
PHP_OCI_ZVAL_TO_DESCRIPTOR(tmp, descriptor);

if (length <= 0) {
php_error_docref(NULL, E_WARNING, "Length parameter must be greater than 0");
php_error_docref(NULL, E_WARNING, "length parameter must be greater than 0");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In such cases, I think capitalization can be retained. While "length" is also the parameter name, it also makes sense if it's just a word.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, I was a bit uncertain about in which direction to go.

return 0;
}
if (!X509_STORE_CTX_init(csc, ctx, x, untrustedchain)) {
php_openssl_store_errors();
php_error_docref(NULL, E_WARNING, "cert store initialization failed");
php_error_docref(NULL, E_WARNING, "Cert store initialization failed");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certificate store, maybe?

@php-pulls php-pulls closed this in d1764ca Jan 17, 2020
@kocsismate kocsismate deleted the consistent-error-messages branch January 17, 2020 13:55
@kocsismate kocsismate changed the title Make error messages more consistent (step 1) Make error messages more consistent Jan 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants